У меня есть
obj1 = {
"place": "{{base_gplaceId}}",
"subPlace": "{{base_gsubPlaceId}}",
"user": "{{base_userId}}",
};
Я хочу
var newArr = [{
"place": "",
"subPlace": "{{base_gsubPlaceId}}",
"user": "{{base_userId}}",
}, {
"place": "{{base_gplaceId}}",
"subPlace": "",
"user": "{{base_userId}}"
}, {
"place": "{{base_gplaceId}}",
"subPlace": "{{base_gsubPlaceId}}",
"user": ""
}];
Ниже приведен мой код
var newArr = [];
const obj1 = {
"place": "{{base_gplaceId}}",
"subPlace": "{{base_gsubPlaceId}}",
"user": "{{base_userId}}",
};
KEYS = Object.keys(obj1);
KEYS.forEach(function (element) {
var object2 = null;
console.log("init:", object2);
object2 = obj1;
console.log("object2:", object2);
console.log("element:", element);
console.log("object2 element VAL:", object2[element]);
object2[element] = "";
console.log("OBJ VAL:", object2, "\n---------------");
newArr.push(object2);
});
console.log(newArr);
То, как в середине пути obj1 устанавливаются пустые значения, и, следовательно, объект2 устанавливается с пустыми значениями, не получая ожидаемых значений.