I want to create a nested array in Javascript and want to group data with same property. I have large number of individual array as given below:
var v=['d','c',['c','e','g','h']];
var w=['c','d',['d','e','f']];
var x=['a','b',['b','c','d']];
var y=['b','a',['a','c','e']];
var u=['e','f',['b','c','e']];
var t=['a','c',['b','c','e','f','g']];
I have tried the following
var z=[];
var a=[];
z.push([t]);
z.push([u]);
z.push([v]);
z.push([w]);
z.push([x]);
z.push([y]);
var k,j;
for(j=0;j<6;j++){
for(k=j+1;k<6;k++){
if(z[j][0]==z[k][1]&& z[j][1]==z[k][0])
a.push([z[j][0], z[j][1], z[j][2],z[k][2]]);
}
}
I couldnot access z array in the way i have used? So how can i get the result in array a?
Expected Output (data in array a)
[['d','c',['c','e','g','h'],['d','e','f']],['a','b',['b','c','d'],['a','c','e']]]
I am new to javascript and i am sorry if i am asking a wrong question. I need array a to return.
Here i want to group data in a array, to those pair which have match i.e 1st array 0 index value with 2nd array 1 index value and 1st array 1 index value with 2nd array 0 index value , and grouped these mathcing in a array and push to array a.
In above expected output, array v is matched with array u so i only want to take value v[0],v[1],v[2] and u[2] in a group and ignore u[0] and u[1]. And push the group to array a.
So that i can return the array a in my program