I am dealing with multi-level hierarchies that need to be displayed in a select list. Once the user selects values from the table column, they should be able to filter by clicking on the column.
var name = ['Akansha', 'Navya'];
var age = ['24', '26'];
var id = ['2345', '34555'];
These values must be passed in JSON format for filtering purposes. To achieve this, we need to follow a specific hierarchy to structure the data correctly.
Values: Array(2)
We need to create an array based on the predefined JSON format that includes the necessary values.
Values: (2)
0: {name: 'Akansha', age: '24', id: '2345'}
1: {name: 'Navya', age: '26', id: '34555'}
To generate the required array list, I have used a loop to iterate through the values.
var nameValues = [];
for(var i=0; i < name.length; i++){
var filterValue = new nam3({
name: name[i],
age: age[i],
id: id[i]
});
nameValues.push(filterValue);
}
console.log(nameValues); // This provides the desired array list with formatted values.
// (2)
// 0: {name: 'Akansha', age: '24', id: '2345'}
// 1: {name: 'Navya', age: '26', id: '34555'}
Next, I need to push these name values into the product filter. The filter ID is 'product'.
product.values.push(nameValues);
However, when pushing the data, it creates a nested array causing an object reference error. The output does not match the required format.
Values: Array(1)
0: Array(2)
0: {name: 'Akansha', age: '24', id: '2345'}
1: {name: 'Navya', age: '26', id: '34555'}
The expected output should be:
Values: (2)
0: {name: 'Akansha', age: '24', id: '2345'}
1: {name: 'Navya', age: '26', id: '34555'}
I am having difficulty passing the name values into the correct place within the JSON array. Any assistance would be greatly appreciated as I am relatively new to JavaScript and troubleshooting this issue.