“JavaScript filter array objek” Kode Jawaban

cara memfilter array objek di javascript

let arr=[{id:1,title:'A', status:true}, {id:3,title:'B',status:true}, {id:2, title:'xys', status:true}];
//find where title=B
let x = arr.filter((a)=>{if(a.title=='B'){return a}});
console.log(x)//[{id:3,title:'B',status:true}]
Handsome Hedgehog

dapat memfilter digunakan pada objek dalam javascript

var heroes = [
	{name: “Batman”, franchise: “DC”},
	{name: “Ironman”, franchise: “Marvel”},
	{name: “Thor”, franchise: “Marvel”},
	{name: “Superman”, franchise: “DC”}
];

var marvelHeroes =  heroes.filter(function(hero) {
	return hero.franchise == “Marvel”;
});

// [ {name: “Ironman”, franchise: “Marvel”}, {name: “Thor”, franchise: “Marvel”} ]
Bright Beaver

Filter JavaScript Array

var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(word => word.length > 6);

console.log(result);
White Browed Owl

cara memfilter array berdasarkan daftar objek di javascript

var array = ['Jane','Donna','Jim','Kate']
var objects = [{name:'Jane', age:25},{name:'Jim', age:30}]

//finds the items in the array that have names within the array of objects.
var filtered = array.filter(r => objects.findIndex(obj => obj.name == r) > -1 )
console.log(filtered)
Busy Bird

JavaScript filter array objek

let people = [
  { name: "Steve", age: 27, country: "America" },
  { name: "Jacob", age: 24, country: "America" }
];

let filteredPeople = people.filter(function (currentElement) {
  // the current value is an object, so you can check on its properties
  return currentElement.country === "America" && currentElement.age < 25;
});

console.log(filteredPeople);
// [{ name: "Jacob", age: 24, country: "America" }]
Wicked Wryneck

JavaScript filter array objek

function isBigEnough(value) {
  return value >= 10
}

let filtered = [12, 5, 8, 130, 44].filter(isBigEnough)
// filtered is [12, 130, 44]
Silly Stork

Jawaban yang mirip dengan “JavaScript filter array objek”

Pertanyaan yang mirip dengan “JavaScript filter array objek”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya