How to directly get value from array via key in node.js -


i'ld price value directly via categoryname key in following array without loop node.js. possible?

priceitem [     { _id: 561e92d7b5737103130a374b,       price: ‘1000',       categoryname: '561e7cbd288906ab3fa3b52b' }     { _id: 561e92d7b5737103130a374c,       price: ‘2000',       categoryname: '561e7cc3288906ab3fa3b52c' }     { _id: 561e92d7b5737103130a374d,       price: ‘3000',       categoryname: '561e3c3aabf5d47634c465bd' }     { _id: 561e92d7b5737103130a374e,       price: ‘4000',       categoryname: '561e3c3eabf5d47634c465be' }     { _id: 561e92d7b5737103130a374f,       price: ‘5000',       categoryname: '561e6439249dced339d529a1’ }     ] 

i think acceptable:

function getpricebycategory(categoryname) {     var retval = '';     (var = 0; < priceitem.length; i++) {         if (priceitem[i].categoryname === categoryname) {             retval = priceitem[i].price;             break;         }     }     return retval; } 

also, think above data not multi-dimensional array single array of objects.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -