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);
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);
javascript get array object by id
myArray.find(x => x.id === '45').foo;
array.filter in js
var numbers = [1, 3, 6, 8, 11];
var lucky = numbers.filter(function(number) {
return number > 7;
});
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);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us