[Vuejs]-Use slice on javascript object to loop for all elements except first two?

0👍

I am not that pro in js but first check this url

How to loop through a plain JavaScript object with the objects as members?

this just to get maybe an idea

How can I slice an object in Javascript?

so I will give you a logic where you may get a solution
if you won’t get answer from above
when finished from url and get clear understand

create a function where it iterate over objects
from what I suggest

then create a variable =1
if var_inc==1 or var-==2
continue
else
do whatever

then do a for loop to loop over over objects
then do that function
just get the logic maybe you get it..

❤🌷😅

0👍

JS objects don’t store the order of elements like arrays. In the general case, there is no such thing as order of specific key-value pairs. However, you can iterate through object values using some utility libraries (like underscore https://underscorejs.org/#pairs), or you could just use raw js to do something this:

// this will convert your object to an array of values with arbitrary order
Object.keys(obj).map(key => obj[key])

// this will sort keys alphabetically
Object.keys(obj).sort().map(key => obj[key])

Note that some browsers can retain order of keys when calling Object.keys() but you should not rely on it, because it isn’t guaranteed.
I would suggest to just use array of objects to be sure of order like this:

[{ key: "First", value: 1 }, { key: "Second", value: 2}]

0👍

If you just want to delete the properties of the objects then you can use delete keyword.

delete Obj['First']
delete Obj['Second']`

This would delete both the keys and object would have only ‘Third’ key

Leave a comment