I have a function that I'm trying to add a new array to the object. I keep getting an error 'target.push is not a function'.
Here is my function
function targetChange(target, source) {
Object.keys(source).forEach(function(keys) {
for(i=0; i<source.length; i++) {
target[keys].push(source[keys]);
}
});
console.log(target);
}
data:
source = {
BasinId: 123,
subBasinId: 45,
SubBasinName: newSubBasin
}
target = {
BasinId: (array of hundreds of ids),
subBasinId: (array of hundreds of ids),
SubBasinName: (array of hundreds of names)
}
I want to return source inside target.. I want to just add the new values to the existing object
I'm passing in an object as target that is set up like this {key: value, key: value, ...}. The source is set up the same way, but I can't seem to get it to add the new source to the target. Any ideas?? I've been stuck on this one for awhile now.
Object.keys(source).forEach(function(keys) {is already looping through the keys!console.log(target);at the beginning of your function? Are you sure,target[SAMPLE_KEY]is an array? (Or has the methodpush)?