javascript - How to use a for loop through unknown value -


i have array shown below. within javascripti need console out customer numbers, of objects existing employees not have customer , therefore not consoling out of employees. help!

i have tried doing if(!tickets[k].customernumber){console.log{"undefined")} still not seem work.

for (var k = 0; k < tickets.length; k++) {     console.log(tickets[k].name)  [ { id: 506652,     name: 'sara johns',     age: '26',     occupation: 'architect',     status: 'new',     customernumber: 26222234 }, { id: 502452,     name: 'emily johnson',     age: '22',     occupation: 'architect',     status: 'existing' }, { id: 326652,     name: 'claire stevens',     age: '23',     occupation: 'junior architect',     status: 'new',     customernumber: 26222234 } 

this print customernumbers, skipping records not have one:

tickets.filter(function(item) {     return item.customernumber; }).foreach(function(item) {     console.log(item.customernumber); }); 

note duplicate ids not filtered out.

you can check mdn more info on array.prototype.filter() , array.prototype.foreach().


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -