Can I loop through a javascript object in reverse order?

后端 未结 4 724
感情败类
感情败类 2021-02-03 17:44

So I have a JavaScript object like this:

foo = {
  \"one\": \"some\",
  \"two\": \"thing\",
  \"three\": \"else\"
};

I can loop this like:

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-03 18:22

    This answer is similar to a couple of the others, but some users might find the code below easier to copy-paste for their own uses:

    Object.keys(foo).reverse().forEach(function(key) { console.log(foo[key]) });
    

    For an object "foo" as described in the question, this code will output the object elements in reverse order: "else", "thing", "some"

提交回复
热议问题