According to these answers, I should be able to search object by the multiple values.
How to find a value in a multidimensional object/array in Javascript?
Javascript: How to filter object array based on attributes?
Search multi-dimensional array JavaScript
Unfortunately filter()
doesn't return anything. Same goes for jQuery's grep()
.
Google 5 pages, still can't find the solution.
Please help. Thanks
https://jsfiddle.net/4z90rvk3/
var itemPrices = {
'1': { 'catid': '1', 'typeid': '1', 'price': '1000' },
'2': { 'catid': '1', 'typeid': '2', 'price': '1000' },
'3': { 'catid': '1', 'typeid': '3', 'price': '1100' },
'4': { 'catid': '2', 'typeid': '1', 'price': '1000' },
'5': { 'catid': '2', 'typeid': '2', 'price': '1000' },
'6': { 'catid': '2', 'typeid': '3', 'price': '1100' },
'7': { 'catid': '3', 'typeid': '1', 'price': '1200' },
'8': { 'catid': '3', 'typeid': '2', 'price': '1200' },
'9': { 'catid': '3', 'typeid': '3', 'price': '1300' },
'10': { 'catid': '4', 'typeid': '1', 'price': '1200' },
'11': { 'catid': '4', 'typeid': '2', 'price': '1200' },
'12': { 'catid': '4', 'typeid': '3', 'price': '1300' },
};
var price = itemPrices.filter(function(item) { return item.typeid == 1 && item.catid == 2; });
$('body').append(price);