JavaScript Program to Extract Given Property Values from Objects as Array Using For Loop Method

Hello, friend today we are going to see clearly what we are going to see in the article JavaScript Program to Extract Given Property Values from Objects as Array Using For Loop Method. We hope you find this article very useful.

JavaScript Program to Extract Given Property Values from Objects as Array Using For Loop Method

JavaScript Program to Extract Given Property Values from Objects as Array Using For Loop Method

// program to extract value as an array from an array of objects

function extractValue(arr, prop) {

    let extractedValue = [];

    for (let i=0; i < arr.length ; ++i) {

        // extract value from property
        extractedValue.push(arr[i][prop]);
    }
    return extractedValue;
}

const objArray = [{a: 1, b: 2}, {a: 4, b: 5}, {a: 8, b: 9}];

// passing an array of objects and property 'a' to extract
const result = extractValue(objArray, 'a');
console.log(result);

Read Also: JavaScript Program to Merge Two Arrays and Remove Duplicate Items Using concat() and for Loop

Final Words

JavaScript Program to Extract Given Property Values from Objects as Array Using For Loop Method We hope you find the article useful and will see you in the next article.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment