close

How to convert Map keys to array?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to convert Map keys to array? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How to convert Map keys to array ?

  1. How to convert Map keys to array ?

    to convert Map keys to array I need something similiar with angular reactive form:
    let myMap = new Map().set(0, {status: 'VALID'}).set(1, {status: 'INVALID'}); let mapToArray = Array.from(myMap.values()); let isValid = mapToArray.every(x => x.status === 'VALID');

  2. How to convert Map keys to array ?

    to convert Map keys to array I need something similiar with angular reactive form:
    let myMap = new Map().set(0, {status: 'VALID'}).set(1, {status: 'INVALID'}); let mapToArray = Array.from(myMap.values()); let isValid = mapToArray.every(x => x.status === 'VALID');

Method 1

Map.keys() returns a MapIterator object which can be converted to Array using Array.from:

let keys = Array.from( myMap.keys() );
// ["a", "b"]

EDIT: you can also convert iterable object to array using spread syntax

let keys =[ ...myMap.keys() ];
// ["a", "b"]

Method 2

I need something similiar with angular reactive form:

let myMap = new Map().set(0, {status: 'VALID'}).set(1, {status: 'INVALID'});
let mapToArray = Array.from(myMap.values());
let isValid = mapToArray.every(x => x.status === 'VALID');

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment