I'm using vuejs and laravel. In component, i have:
data(): {
return {
data: []
}
}
After fetching, i have this. I want to load more data if user scroll, so i have to add new object into data.
I tried Object.assign, push... but the properties had be overwritten. I also loop the data and add new object but not work either...
I want something like:
obj1 = {0: value1, 1: value2};
obj2 = {0: value3, 1: value4};
=> obj = {0: value1, 1: value2, 3: value3, 4: value4};
Any idea? Tks!
You can extract the values from the object using
Object.values()
, then join both of the values usingarray#concat
then usingObject.assign()
create your object.You can also use
array#reduce
instead ofObject.assign
.