Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

move an object in array by latest clicked

var data = [
    { id: "fmgbwe45", age: 24, gender: "male"   },
    { id: "kjregh23", age: 27, gender: "female" }, 
    { id: "kjfdhg87", age: 30, gender: "male" }, 
    { id: "lsdjfk43", age: 10, gender: "female" }, 
]

var stringToFilter = 'kjfdhg87';   //this holds 'kjfdhg87'
data.unshift(data.splice(data.findIndex(item => item.id === stringToFilter), 1)[0])
console.log(data);
 Run code snippet
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #move #object #array #latest #clicked
ADD COMMENT
Topic
Name
6+2 =