Monday, February 29, 2016

Summary - JavaScript in Work

1. Get keys of an object
Object.keys(<object>); //return an array,  no order guarantee, needs to be sorted when need

2. JSON <-> String
   JSON.parse(<string>);
   JSON.stringify(<json obj>);

3. Loop array
<array>.forEach(function(element, index, array){
//xxxx
});

4. Rename keys in an object

for(var key in object){
    object[newKey] = object[key];
    delete object[key];
}

No comments:

Post a Comment