You can do it with .map(). Immagine a fetch of database rows.

With arrow function

To have a reusable arrayColumn(array, column) function:

const array = [
    {id: 1, name: 'foo'},
    {id: 2, name: 'bar'},
];
const arrayColumn = (array, column) => {
    return array.map(item => item[column]);
};
const names = arrayColumn(array, 'name');
console.log(names);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Or you can use .map directly:

const array = [
    {id: 1, name: 'foo'},
    {id: 2, name: 'bar'},
];
const names = array.map(item => item.name);
console.log(names);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Before ES6 (2015)

var array = [
    {id: 1, name: 'foo'},
    {id: 2, name: 'bar'},
];
function arrayColumn(array, columnName) {
    return array.map(function(value,index) {
        return value[columnName];
    })
}
var names = arrayColumn(array, 'name');
console.log(names);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Answer from fabpico on Stack Overflow
🌐
GitHub
github.com › rambkk › Javascript-array_column
GitHub - rambkk/Javascript-array_column: Javascript array_column function like PHP · GitHub
array_column(ARRAY, KEY/INDEX COLUMN for output, (optional) OUTPUT KEY/INDEX COLUMN to be used as key/index for the output)
Author: rambkk
Discussions

javascript - Get column from a two dimensional array - Stack Overflow
How can I retrieve a column from a 2-dimensional array and not a single entry? I'm doing this because I want to search for a string in one of the columns only so if there is another way to accomplish More on stackoverflow.com
🌐 stackoverflow.com
javascript - Get column in array of arrays - Stack Overflow
Given a JavaScript array: var m = someNumber; var n = someOtherNumber; var myArray = // new m x n Array; What's the fastest way to get a column (rather than a row) from the array? Ex structure: More on stackoverflow.com
🌐 stackoverflow.com
Column of a matrix [array]
I solved this Freecodecamp challenge, pushing the largest(row) number in each array into the newArr · How can i make the code be printed in a column and get this output [1000, 1001, 857, 39] · Why are you hard coding 0? You needed needed a nested loop to go through the rows, so you will similarly ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
6
0
August 13, 2022
add new column in javascript array - Stack Overflow
Now, on button click, I want to add a new column in it. Can anyone let me know how we can do it? ... If you want to add a new attribute in the first element of data try data[0].newcolumnname = 'whatever value' ... You could iterate though the data array and add key & value to each element. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Pluslab
pluslab.net › blog › javascript-array_column › javascript-array_column-js
Javascript array_column.js - PlusLab.net
November 11, 2021 - * (c) Ram Narula You can use this information, kindly do give credit: github.com/rambkk - pluslab.net * Please drop a line to say hello and let me know what kind of project you are working on :-) * * So the general syntax should be: * * array_column(ARRAY, KEY/INDEX COLUMN for output, (optional) OUTPUT KEY/INDEX COLUMN to be used as key/index for the output) * * (If KEY/INDEX COLUMN is null, the output will be the full ARRAY re-indexed with KEY/INDEX COLUMN) * * Version: array_column v0.11 (initial release) * * Requirement: might require Javascript ES6 * * NOTE: works on ARRAY of arrays and AR
🌐
Pluslab
pluslab.net › blog › javascript-array_column
Javascript array_column - PlusLab.net
November 11, 2021 - array_column(ARRAY, KEY/INDEX COLUMN for output, (optional) OUTPUT KEY/INDEX COLUMN to be used as key/index for the output)
🌐
IQCode
iqcode.com › code › javascript › javascript-array-column
javascript array column Code Example
November 4, 2021 - //get column in javascript... function getCol(matrix, col){ var column = []; for(var i=0; i<matrix.length; i++){ column.push(matrix[i][col]); } return column; // return column data.. } var array = [new Array(20), new Array(20), new Array(20)]; //..your 3x20 array getCol(array, 0); //Get first column
Find elsewhere
🌐
Locutus
locutus.io › php › array_column
PHP's array_column in TypeScript | Locutus
May 16, 2026 - Or with CommonJS: const { array_column } = require('locutus/php/array/array_column') Use a bundler that supports tree-shaking so you only ship the functions you actually use. Vite, webpack, Rollup, and Parcel all handle this. For server-side use this is less of a concern. These examples are extracted from test cases that automatically verify our functions against their native counterparts. Please note that Locutus uses TypeScript/JavaScript objects as substitutes for PHP arrays, they are the closest we can get to this hashtable-like data structure without rolling our own.
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
Column of a matrix [array] - JavaScript
August 13, 2022 - function largestOfFour(arr) { let newArr = []; for(let i = 0; i < arr.length; i++){ let max = 0; for (let j = 0; j < arr[i].length; j++){ if (arr[i][j] > max){ max = arr[i][j] } } newArr…
🌐
W3Schools
w3schools.com › php › func_array_column.asp
PHP array_column() Function
The array_column() function returns the values from a single column in the input array.
🌐
Sentry
sentry.io › sentry answers › javascript › how can i create a two-dimensional array in javascript?
JavaScript Two-Dimensional Array: Create a Matrix | Sentry
1 month ago - const rows = 4; const columns = 5; let my2DArray = Array(rows) .fill() .map(() => Array(columns).fill(0)); console.log(my2DArray); // [ // [0, 0, 0, 0, 0], // [0, 0, 0, 0, 0], // [0, 0, 0, 0, 0], // [0, 0, 0, 0, 0], // ]; The Array() constructor can be called with or without the new keyword. Both constructions create an array instance. Youtube How Sentry.io saved me from disaster (opens in a new tab) Resources Improve Web Browser Performance - Find the JavaScript code causing slowdowns (opens in a new tab)
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript - MDN Web Docs
// The first column is the index 0 1 0 1 2 2 2 4 8 3 8 18 4 16 32 5 32 50 6 64 72 7 128 98 8 256 128 9 512 162 · The result of a match between a RegExp and a string can create a JavaScript array that has properties and elements which provide information about the match.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-sort-an-array-on-multiple-columns-using-javascript
How to sort an array on multiple columns using JavaScript ? | GeeksforGeeks
July 25, 2024 - We have given an array of objects and the task is to sort the array of elements by 2 fields of the object. There are two methods to solve this problem which are discussed below: Approach 1:First compare the first property, if both are unequal then sort accordingly.If they are equal then do the same ... Given the JavaScript array containing Boolean values.
🌐
TechBrij
techbrij.com › convert-column-to-row-javascript-array-pivot
Pivot a JavaScript Array: Convert a Column to a Row - TechBrij
August 29, 2015 - $(function () { var output = getPivotArray(arr, 0, 1, 2); $('#orgTable').html(arrayToHTMLTable(arr)); $('#pivotTable').html(arrayToHTMLTable(output)); }); ... In this post, we have converted one column to row in JavaScript array and display data accordingly.
🌐
Quora
quora.com › How-do-I-go-via-columns-in-a-2D-array-and-do-some-function-for-them-separately-which-will-return-some-value-for-each-column-Ill-be-comparing-these-values-later-in-JavaScript
How to go via columns in a 2D array and do some function for them separately, which will return some value for each column (I'll be comparing these values later) in JavaScript - Quora
Answer (1 of 2): You can iterate over the columns of a 2D array by using two nested loops, with the outer loop running over the number of columns and the inner loop running over the number of rows for each column. Here's an example: [code]function processColumns(array) { let results = []; f...
🌐
DataTables
datatables.net › reference › api › toArray()
toArray()
This method can be used to create a native JavaScript array which contains the same items as contained in the API instance's result set.
🌐
PHP
php.net › manual › en › function.array-column.php
PHP: array_column - Manual
A list whose rows are arrays or objects, from which a column of values is pulled. If a row is an object, public properties are read directly.