javascriptを初めて使用しています。私はjsonデータの2つのリストを持っています。私はお互いを繰り返す必要があり、キーと値がお互いに一致する場合は、新しいキー値のペアを最初のリストに追加する必要があります。詳細については、次の例を参照してください:あなたは、オブジェクトのように扱う、あなたの顧客オブジェクトを返しますcustomer[i]
としてJavaScript Jsonの値は、等価条件に基づいて追加されます。
customers[i].yourKey = yourValue;
を使用することができます
Example:
//array 1
var customers = [{
CustomerName: 'Customer1',
},
{
CustomerName: 'Customer2',
}];
// array 2
var locations= [{
CustomerName: 'Customer1',
latitude: 555555;
},
{
CustomerName: 'Customer2',
latitude: 666666;
},
{
CustomerName: 'Customer3',
latitude: 777777;
}];
// Iteration of the arrays
for(var i=0; i<customers.length; i++){
for(var j=0;j<locations.length;j++) {
if(customers[i].CustomerName ==locations[j].CustomerName) {
// Here I want to add an element key value pair into existing array if condition get satisfied
customers[i].push(locations[j].lat);
alert(customers[i].lat);
}
}
}
私はあなたの質問をしていない場合:customers.push({key:value}); –