JSFiddle - React, Tailwind, and code Playground
JavaScript
var index = ['a','b','c','d'];
result = [{ b:'Val1', c:'Val2', a:'Val3', d:'Val4' },{ b:'Val5', c:'Val6', a:'Val7', d:'Val8' }];
var finalRes = [];
for (var i = 0; i<result.length; i++){
//We get each slice of result array here
//Lets begin a fresh array of this particular array
thisArray = [];
for (var j = 0; j<index.length; j++){
//Now Preparing the particular Array
var key = index[j]; //Key of Index Array
thisArray[key] = result[i][key]
// What we did just before is:
// We created an Element Inside this Particular Array with reference of index and value of result
}
finalRes.push(thisArray);
}
console.log(finalRes); //Required Array
console.log(finalRes[0]["a"]); //Checking Elements