Quantcast
Channel: Array.filter not return exactly properties of object? - Stack Overflow
Viewing all articles
Browse latest Browse all 7

Array.filter not return exactly properties of object?

$
0
0

I'm trying to understand some built in method of array. Here is my code for small function, I want to display "name" and "category" of each item, which is store in inventory with total value larger than 1000. But when I try to print bigPrice, it always display all of property of each object and I only want to display "name" and "category". Anyone can help?

var products = [{name: 'A', quantity: 2, unitPrice: 100, category: 'Electronic goods'},{name: 'B', quantity: 1, unitPrice: 400, category: 'Electronic goods'},{name: 'C', quantity: 5, unitPrice: 15, category: 'Clothing goods'},{name: 'D', quantity: 2, unitPrice: 95, category: 'Clothing goods'},{name: 'E', quantity: 300, unitPrice: 10, category: 'Home, Garden goods'},{name: 'F', quantity: 60, unitPrice: 150, category: 'Handmade'},{name: 'G', quantity: 10, unitPrice: 105, category: 'Automotive goods'}];var bigPrice = products.filter(function(item) {if (item.quantity * item.unitPrice > 1000) {    return item.name +' || '+ item.category;}});bigPrice;

Viewing all articles
Browse latest Browse all 7

Latest Images

Trending Articles





Latest Images