Skip to main content
No need to repeat tags in title
Source Link
Toby Speight
  • 77.3k
  • 14
  • 95
  • 266

Extract each occurrence from an array of objects (performance)

I have a huge list of 4k+ softwareProductsoftware products.

My goal is simple. I have a list of products. Each of those products has a software value. I would like to extract each software occurrence and covert it into an object in the format {text, id}.

The code below works as I need, but I would like to know if you have a better way to do it.

softwareProducts.reduce((acc = [], {software_id, software_name}) => {
    if (acc.find((row) => row.id === software_id) === undefined) {
        acc.push({
            text: software_name,
            id: software_id
        })
    }
    return acc;
}, []);

Extract each occurrence from an array of objects (performance)

I have a huge list of 4k+ softwareProduct.

My goal is simple. I have a list of products. Each of those products has a software value. I would like to extract each software occurrence and covert it into an object in the format {text, id}.

The code below works as I need, but I would like to know if you have a better way to do it.

softwareProducts.reduce((acc = [], {software_id, software_name}) => {
    if (acc.find((row) => row.id === software_id) === undefined) {
        acc.push({
            text: software_name,
            id: software_id
        })
    }
    return acc;
}, []);

Extract each occurrence from an array of objects

I have a huge list of 4k+ software products.

My goal is simple. I have a list of products. Each of those products has a software value. I would like to extract each software occurrence and covert it into an object in the format {text, id}.

The code below works as I need, but I would like to know if you have a better way to do it.

softwareProducts.reduce((acc = [], {software_id, software_name}) => {
    if (acc.find((row) => row.id === software_id) === undefined) {
        acc.push({
            text: software_name,
            id: software_id
        })
    }
    return acc;
}, []);
clarify, fix grammar
Source Link
ggorlen
  • 3.8k
  • 2
  • 18
  • 28

I have a huge list of 4k+ softwareProduct.

My goal is simple,. I have a list of products. Each of those products havehas a software value. I would like to extract each software occurrence and covert it into an object in the format {text, id}{text, id}.

The code bellowbelow works as I need, but I would like to know if you have a better way to do it.

softwareProducts.reduce((acc = [], {software_id, software_name}) => {
    if (acc.find((row) => row.id === software_id) === undefined) {
        acc.push({
            text: software_name,
            id: software_id
        })
    }
    return acc;
}, []);
softwareProducts.reduce((acc = [], {software_id, software_name}) => {
    if (acc.find((row) => row.id === software_id) === undefined) {
        acc.push({
            text: software_name,
            id: software_id
        })
    }
    return acc;
}, []);

I have a huge list of 4k+ softwareProduct.

My goal is simple, I have a list of products. Each of those products have a software value. I would like to extract each software occurrence and covert it into an object {text, id}

The code bellow works as I need, but I would like to know if you have a better way to do it.

softwareProducts.reduce((acc = [], {software_id, software_name}) => {
    if (acc.find((row) => row.id === software_id) === undefined) {
        acc.push({
            text: software_name,
            id: software_id
        })
    }
    return acc;
}, []);

I have a huge list of 4k+ softwareProduct.

My goal is simple. I have a list of products. Each of those products has a software value. I would like to extract each software occurrence and covert it into an object in the format {text, id}.

The code below works as I need, but I would like to know if you have a better way to do it.

softwareProducts.reduce((acc = [], {software_id, software_name}) => {
    if (acc.find((row) => row.id === software_id) === undefined) {
        acc.push({
            text: software_name,
            id: software_id
        })
    }
    return acc;
}, []);
edited body
Source Link
toolic
  • 3.9k
  • 2
  • 16
  • 52

I have a huge list of 4k+ softwareProduct.

My goal is simple, I have a list of products. Each of those products have a software value. I would like to extract each software occurrence and covert it into an object {text, id}

The code bellow works as I need, but I would like to know if you have a better way to do it :).

softwareProducts.reduce((acc = [], {software_id, software_name}) => {
    if (acc.find((row) => row.id === software_id) === undefined) {
        acc.push({
            text: software_name,
            id: software_id
        })
    }
    return acc;
}, []);

I have a huge list of 4k+ softwareProduct.

My goal is simple, I have a list of products. Each of those products have a software value. I would like to extract each software occurrence and covert it into an object {text, id}

The code bellow works as I need, but I would like to know if you have a better way to do it :)

softwareProducts.reduce((acc = [], {software_id, software_name}) => {
    if (acc.find((row) => row.id === software_id) === undefined) {
        acc.push({
            text: software_name,
            id: software_id
        })
    }
    return acc;
}, []);

I have a huge list of 4k+ softwareProduct.

My goal is simple, I have a list of products. Each of those products have a software value. I would like to extract each software occurrence and covert it into an object {text, id}

The code bellow works as I need, but I would like to know if you have a better way to do it.

softwareProducts.reduce((acc = [], {software_id, software_name}) => {
    if (acc.find((row) => row.id === software_id) === undefined) {
        acc.push({
            text: software_name,
            id: software_id
        })
    }
    return acc;
}, []);
Source Link
Loading