Change all null to '' in array of Objects (javascript) -


i have array of objects shown below

object {results:array[3]}     results:array[3]         [0-2]              0:object                     id=null                          name: "rick"                     value: "34343"              1:object                     id=2                          name: null                     value: "2332"              2:object                     id=2                          name:'mike'                     value: null 

as can see, in 1 object have id null, 2nd object has name null , 3rd object has value null. each object has property null.

i want loop through of these , replace null ''. can let me know how achieve this...

you needed google looping through objects. here's example:

looping through every key (if keys unknown or want same keys)

for (var i=0; i<arr.length; i++) {   var obj = arr[i];   if (typeof obj === 'object') {     (k in obj) {       v = obj[k];       if (v === null || v === undefined) {         obj[k] = '';       }     }   } } 

if keys known:

for (var i=0; i<arr.length; i++) {   var obj = arr[i];   if (obj.name === undefined || obj.name === null) {     obj.name = '';   } } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -