Answers for "filter array by id"

3

javascript filter array of objects by id

const myArray = [{id: 1, name:'pipi'}, {id: 2, name:'popo'}];
const id = 2;

const variableOne = myArray.filter(itemInArray => itemInArray.id === id);
console.log(cariableOne[0].name);
Posted by: Guest on February-01-2021
4

javascript get array object by id

myArray.find(x => x.id === '45').foo;
Posted by: Guest on May-25-2020
2

array.filter in js

var numbers = [1, 3, 6, 8, 11];

var lucky = numbers.filter(function(number) {
  return number > 7;
});
Posted by: Guest on June-11-2020
0

filter array by keyword

var data = [
  {email: "[email protected]",nama:"User A", Level:"Super Admin"},
  {email: "[email protected]",nama:"User B", Level:"Super Admin"},
  {email: "[email protected]",nama:"User C", Level:"Standart"},
  {email: "[email protected]",nama:"User D", Level:"Standart"},
  {email: "[email protected]",nama:"User E", Level:"Admin"},
  {email: "[email protected]",nama:"User F", Level:"Standart"}
];
var filter = "Level";
var keyword = "Standart";

var filteredData = data.filter(function(obj) {
	return obj[filter] === keyword;
});

console.log(filteredData);
Posted by: Guest on December-28-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language