我有一个对象数组,我想创建一个单独的对象,如果有一个公共密钥,它将在该密钥下创建一个新数组。比方说,我有以下数组:
[{
"Steering": ["Steering Type : EPAS with Pull Drift Compensation technology"],
"Power \u0026 Performance": ["1.5L Petrol Ti-VCT MT : ", "1.5L Petrol Ti-VCT AT : ", "1.0L Petrol Ecoboost MT : ", "1.5L Diesel DV5 MT : "],
"Wheels and Tyres": ["Tyres : 195 / 65 R15", "Wheels in inch : 15\" Steel Wheels"],
}, {
"INSTRUMENTATION": ["Tachometer : ", "Door Ajar Indicator : ", "Low Fuel Warning Lamp : ", "Distance To Empty (DTE) Display : ", "Headlamp on Key-off warning : "],
"TYRES \u0026 WHEELS": ["Tyres : 175/65R14", "Wheel Size : 14\" Steel(35.6)cms"],
"BRAKES": ["Front : Ventilated Discs", "Rear : Self Adjusting Drums "],
}, {
"INSTRUMENTATION": ["Tachometer : ", "Door Ajar Indicator : ", "Low Fuel Warning Lamp : ", "Distance To Empty (DTE) Display : ", "Headlamp on Key-off warning : "],
"TYRES \u0026 WHEELS": ["Tyres : 175/65R14", "Wheel Size : 14\" Alloy (35.6)cms"],
"BRAKES": ["Front : Ventilated Discs", "Rear : Self Adjusting Drums "],
}]
我有重复的INSTRUMENTATION
,BRAKES
,TYRES & WHEELS
键。
我想创建一个不会重复键的单个对象,如果已存在相同的键,则会创建一个新的子数组对象。与INSTRUMENTATION
,BRAKES
和TYRES & WHEELS
键一样,将创建一个新的数组对象。
除了jQuery,我不想使用任何第三方关键字。
预期结果应该是: -
[
{
"Steering": [
"Steering Type : EPAS with Pull Drift Compensation technology"
],
"Power & Performance": [
"1.5L Petrol Ti-VCT MT : ",
"1.5L Petrol Ti-VCT AT : ",
"1.0L Petrol Ecoboost MT : ",
"1.5L Diesel DV5 MT : "
],
"Wheels and Tyres": [
"Tyres : 195 \/ 65 R15",
"Wheels in inch : 15\" Steel Wheels"
],
"INSTRUMENTATION": [
[
"Tachometer : ",
"Door Ajar Indicator : ",
"Low Fuel Warning Lamp : ",
"Distance To Empty (DTE) Display : ",
"Headlamp on Key-off warning : "
],
[
"Tachometer : ",
"Door Ajar Indicator : ",
"Low Fuel Warning Lamp : ",
"Distance To Empty (DTE) Display : ",
"Headlamp on Key-off warning : "
]
],
"TYRES & WHEELS": [
[
"Tyres : 175\/65R14",
"Wheel Size : 14\" Steel(35.6)cms"
],
[
"Tyres : 175\/65R14",
"Wheel Size : 14\" Alloy (35.6)cms"
]
],
"BRAKES": [
[
"Front : Ventilated Discs",
"Rear : Self Adjusting Drums "
],
[
"Front : Ventilated Discs",
"Rear : Self Adjusting Drums "
]
]
}
]