JSFiddle - React, Tailwind, and code Playground
by Arif Hasan
JavaScript
var values = [
["arif", "26", "male", "good"],
["shamima", "27", "female", "bad"]
]
var keys = ["name", "age", "gender", "status"];
var finalResult = values.map((data_array) => {
var basic_values = {
[keys[0]]: data_array[0],
[keys[1]]: data_array[1]
}
var other_values = {}
var array = []
data_array.forEach((item, index) => {
if (index === 0) {
return
} else if (index === 1) {
return
} else {
other_values[keys[index]] = item
array.push(other_values)
}
})
// console.log(other_values)
// console.log(array)
for (var i in array) {
return {
'basic': basic_values,
'other': [array[i]]
}
}
})
console.log(finalResult);