Tuesday 1 October 2019

javascript - Pushing an object to beginning of an array

I have this array.



var array = [
{

title:'Fish'
id: 1
},
{
title: 'Meat'
id:2
}
]



It's used in a drop down. I'd like to add an option at the top:



{
title:'All'
id:3
}


How do I push this object to the beginning of the array? If I use push, then it's placed at the end.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...