1

I'm having a utility function that converts a map into a list. It is supposed to still have the key values attached to it, but for some reason it doesn't. Rather I need to read of by index, of which is not really useful for my use case. Do someone know how to preserve keys when I transfer from a map? Here's my source

function getMetaStateArray(metaStateArrayOrObject) {
  let metaStateArray;

  if (metaStateArrayOrObject && Immutable.Map.isMap(metaStateArrayOrObject)) {
    metaStateArray = metaStateArrayOrObject.toList();
  }
  else {
    metaStateArray = metaStateArrayOrObject;
  }

  return metaStateArray;
}

1 Answer 1

1

Solved it by making a list Wrapper around my map, while doing List.of() inside the wrapper, so the map inside won't turn into a regular array:

metaStateArray = List(List.of(metaStateArrayOrObject));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.