Here is a sample of Javascript object and code to consider:
Javascript Object
{
"thing":{
"data":"some data",
"thumb":"some data",
"data1":"some data",
"data2":"some data",
"data3":"some data",
},
"extra1":[
{
"extradata1":"some data",
"extradata2":"some data",
"extradata3":"some data",
"extradata4":"some data"
},
{
"extradata1":"some data",
"extradata2":"some data",
"extradata3":"some data",
"extradata4":"some data"
}
],
"extra2":[
{
"hightlighted": false,
"extradata2":"some data",
},
{
"hightlighted": false,
"extradata2":"some data",
},
{
"hightlighted": true,
"extradata2":"some data",
},
{
"hightlighted": false,
"extradata2":"some data",
}
]
}
The task is to locate an object in 'extra2' where the value is true, remove it from its current position, and insert it back at the beginning of the 'extra2' object.
The solution attempt involves:
for (var i=0; i<object.extra2.length; i++){
if (object.extra2[i].highlighted === true) {
highlightStore = object.extra2[i];
delete object.extra2[i]
object.extra2.unshift(highlightStore)
}
}
However, troubleshooting is needed as the intended functionality is not yet achieved.