I am faced with a scenario where I have two arrays within an Angular framework.
One of the arrays is a regular array named A, containing values such as ['Stock_Number', 'Model', 'Type', 'Bill_Number']
The other array is an associated array B structured as follows:
0:[
{
'Stock_Number': 'GTH738',
'Model': 'sample_model',
'Type': 'sample_type',
'Bill_Number': 7784754,
'some_prop1': 'prop1_val',
'some_prop2': 'prop2_val'
}
];
It is important to note that both arrays are dynamic in nature. Array B contains more columns than Array A, with the keys of B being a subset of A. My goal is to create a new array C consisting only of elements present in A. To accomplish this, I need to check if the key exists in B. Below is the code snippet I am using:
for(var i=0,j=0; i<B.length,j<A.length; i++,j++){
if (!B.hasOwnProperty(A)) {
var value = A[j];
console.log('if-'+value); //printing value
console.log(B[0].value); // printing undefined
// C.push(B[0].value);
}else{
//some code
}
}
The resulting array should resemble the structure below:
{
'Stock_Number': 'GTH738',
'Model': 'sample_model',
'Type': 'sample_type',
'Bill_Number': 7784754
}
I would appreciate any suggestions or guidance on how to achieve this task effectively.