Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Javascript how do i dynamically find keys in my array?

I’m trying to find all the keys that are in my array to figure out if some keys already exist in there. Tho when I try to put in the keys seperate like this:

console.log(this.UrlArray.find(({color_ids}) => color_ids));

It works, but if I try doing it with the variable with the actual keys in it:

console.log(this.UrlArray.find(({prefixEqual}) => prefixEqual));

It doesn’t work. The values that belong to the keys aren’t important, but I stil can’t figure out how to do it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Array example:

(3) [{…}, {…}, {…}]
  0:
    bd_shoe_size_ids: Array(2)
      0: "6601"
      1: "6598"
    length: 2
    [[Prototype]]: Array(0)
    [[Prototype]]: Object
  1:
    color_ids: Array(2)
      0: "6056"
      1: "6044"
    length: 2
    [[Prototype]]: Array(0)
    [[Prototype]]: Object
  2:
    manufacturer_ids: Array(2)
      0: "5875"
      1: "5866"
    length: 2
    [[Prototype]]: Array(0)
    [[Prototype]]: Object
  length: 3
[[Prototype]]: Array(0)

I asked something like this before, but I got linkes to answers that had nothing to do with what I’m trying to do and it closed.

As desired outputs I just wanna see bd_shoe_size_ids, color_ids and manufacturer_ids when I console log it.

>Solution :

const data = [
    { bd_shoe_size_ids: [1, 2] },
    { color_ids: [3, 4] },
    { manufacturer_ids: [5, 6] },
];

const output = data.map(Object.keys).flat();

console.log(output);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading