Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to filter an array of objects in 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}]
Comment

javascript filter array of objects

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" }]
Comment

how to filter list of objects by an array in javascript

var array = ['cat','dog','fish','goat']  
var objects = [{pet:'cat', color:'brown'},{pet:'dog', color:'black'},{pet:'gecko', color:'green'}]

//finds the objects that match something in the list with the key pet.
var filteredObjects = objects.filter(function(obj){
    return array.indexOf((obj.pet).toString()) > -1;
  });
console.log(filteredObjects)
Comment

Filter Array of Objects with Array of Objects

const myArray = [{ userid: "100", projectid: "10", rowid: "0" }, { userid: "101", projectid: "11", rowid: "1"}, { userid: "102", projectid: "12", rowid: "2" }, { userid: "103", projectid: "13", rowid: "3" }, { userid: "101", projectid: "10", rowid: "4" }];
const myFilter = [{ userid: "101", projectid: "11" }, { userid: "102", projectid: "12" }, { userid: "103",  projectid: "11"}];

const myArrayFiltered = myArray.filter((el) => {
  return myFilter.some((f) => {
    return f.userid === el.userid && f.projectid === el.projectid;
  });
});

console.log(myArrayFiltered);
Comment

javascript filter array of objects by array

var arr = [1,2,3,4],
    brr = [2,4],
    res = arr.filter(f => !brr.includes(f));
console.log(res);
Comment

how to filter an array by list of objects in 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)
Comment

filter array inside array of objects javascript

const initialState = [
     {id:1 ,name: 'Product A', image: 'pic-001.jpg', tags: ['nature', 'camping', 'outdoor']},
     {id:2 ,name: 'Product B', image: 'pic-002.jpg', tags: ['winter', 'hiking', 'camping', 'snow']},
     {id:3 ,name: 'Product C', image: 'pic-003.jpg', tags: ['vacation', 'family', 'kids', 'river', 'lake', 'fishing']}
];

const filterByTags = ['nature', 'family'];

const filterByTagSet = new Set(filterByTags);

const result = initialState.filter((o) => 
  o.tags.some((tag) => filterByTagSet.has(tag))
);

console.log(result);
 Run code snippet
Comment

filter object array

objects.filter((value, index, self) => {
  return self.findIndex(v => v.actor.name === value.actor.name) === index;
})
Comment

javascript filter array of objects

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

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

PREVIOUS NEXT
Code Example
Javascript :: javascript concatenation 
Javascript :: react class component input text with clear button 
Javascript :: merge in mongodb 
Javascript :: difference 
Javascript :: in in sequelize 
Javascript :: jquery deparam 
Javascript :: react hook form with controlled input 
Javascript :: yup.array not working 
Javascript :: node js gitignore 
Javascript :: object assign js 
Javascript :: some js es6 
Javascript :: how to find keycode in javascript 
Javascript :: javascript generate random string from array 
Javascript :: How to Subtract the numbers in the array, starting from the right in javascript 
Javascript :: Loading react circular progress 
Javascript :: jquery clone table row 
Javascript :: ja display snippet from text string 
Javascript :: adding data attributes to react-select 
Javascript :: can we use setstate inside build 
Javascript :: how to convert string to pascal case in javascript 
Javascript :: express ubuntu ERR_CONNECTION_REFUSED 
Javascript :: use obj property inside itself 
Javascript :: foreach and replace item based on condition 
Javascript :: Ocultar un elemento cuando la ventana cambia de tamaño css 
Javascript :: .tolowercase 
Javascript :: Symbol Methods javascript 
Javascript :: react state not updating immediately 
Javascript :: sendgrid mail unique args 
Javascript :: javascript find first element of array 
Javascript :: react proxy error: could not proxy request from localhost:3000 to http localhost:5000 econnreset 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =