Home » Javascript » Pop array element based on object property and value

Pop array element based on object property and value

Posted by: admin October 18, 2018 Leave a comment

Questions:

I was wondering how can I extract a single object from an array by an object property and value,
Something in the line of:

let arr = [{temp:36, night: false}, {temp:12, night: true}, {temp:24, night: true}]
let Obj = arr.pop({night:true})
// obj: {temp:12, night: true}
// arr now: [{temp:36, night: false}, {temp:24, night: true}]

Any advice?

Answers: