Tuesday, November 17, 2015

jquery nested json example

 shareNoteDocumentJson.push({
                    userId: '1',
                    notes: [
                        { noteId: 'n1', note: 'note1' },
                        { noteId: 'n2', note: 'note2' },
                        { noteId: 'n3', note: 'note3' },
                    ],
                    documents: [
                        { documentId: 'd1', document: 'document1' },
                        { documentId: 'd1', document: 'document2' },
                        { documentId: 'd1', document: 'document3' },
                    ]
                });

jquery check if radiobutton is checked

 if($('#radio_button').is(':checked')) { alert("it's checked"); }

Monday, November 16, 2015

jquery radio button checked event by name

  $('input:radio[name="share"]').change(function () {
                alert(this);
            });

Friday, October 30, 2015

Remove duplicate objects in an array of object in JavaScript

function remove_duplicates(objectsArray) {
    var usedObjects = {};

    for (var i=objectsArray.length - 1;i>=0;i--) {
        var so = JSON.stringify(objectsArray[i]);

        if (usedObjects[so]) {
            objectsArray.splice(i, 1);

        } else {
            usedObjects[so] = true;          
        }
    }

    return objectsArray;

}