array filter matching value

by Seetpal Singh

JavaScript

var jsObjects = [
  {a: 1, b: 2}, 
  {a: 3, b: 4}, 
  {a: 5, b: 6}, 
  {a: 7, b: 8}
];

/* var filterObj = jsObjects.filter(function(e) {   return e.b == 6;} );	*/
var filterObj = jsObjects.filter(e => e.b == 6);

/* const filterObj = jsObjects.filter(item => item.b == 2); */


console.log(filterObj);


/* myObject = { 'a': 1, 'b': 2, 'c': 3 };

let keysArray = Object.value(key[a] == 1 );

console.log(keysArray);	*/

const arr = [
  {
    name: 'string 1',
    arrayWithvalue: '1,2',
    other: 'that',
  },
  {
    name: 'string 2',
    arrayWithvalue: '2',
    other: 'that',
  },
  {
    name: '2',
    arrayWithvalue: '2,3',
    other: 'that',
  },
  {
    name: 'string 2',
    arrayWithvalue: '4,5',
    other: 'that',
  },
  {
    name: 'string 2',
    arrayWithvalue: '4',
    other: 'that',
  },
];

const items = arr.filter(item => item.name == '2');

console.log(items);