How do I use the following object key?

  • 0
    How do I use the following object key? For example, if we know that the object has a key '5', then how can we use the key '7' that follows it, that is, not knowing the key itself, refer to it, knowing the previous key '5'
    const obj = {
     '1': QWE,
     '5': ASD,
     '7' : ZXC
    }
    JavaScript Anonymous, Jan 31, 2020

  • 3 Answers
  • 0
    const obj = {
    '1': QWE,
    '5': ASD,
    '7' : ZXC
    }

    const keys = Object.keys(obj).sort();
    const nextKey = keys[keys.indexOf("5")+1];

    console.log(obj[nextKey])
    Lincoln Sutton

  • 0
    maybe this will help https://developer.mozilla.org
    Anonymous

  • 0
    According to the JS standard, the keys in an object have no ordering.

    Object

    An object is a member of the type Object. It is an unordered collection of properties each of which contains a primitive value, object, or function.
    Luke Perez

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!