Most efficient way to create an array based on other arrays

Discussão em 'Angular' iniciado por SolisQuid, Janeiro 13, 2025.

  1. SolisQuid

    SolisQuid Guest

    I have an array with varying number of objects like so:

    const arrayA = [
    {name: n, value: v}
    {name: n, value: v}
    ...
    {name: n, value: v}
    ]


    I have another array with n number of numbers:

    const arrayB = [1, 13, 28]


    Length of arrayB is less or equal than of arrayA but never higher.

    Now I need to create another array - arrayC: Array<boolean> = []. The length of arrayC should be equal to length of arrayA

    arrayA.length == arrayC.length

    with all false boolean values apart from those with index of every value from arrayB

    I could probably achieve this with bunch of forEach and/or for loops but what I want to know is what would be the most efficient and not resource consuming way to get it.

    Continue reading...

Compartilhe esta Página