How to log only the elements from second level array from a multidimentional array

php get array key by value multidimensional
php get array value by key
php get array value without key
php get value from associative array by key
get specific key value from array php
php array remove keys keep values
multidimensional array to single array php
php multidimensional array

I have the following array and I need to log only the elements from the second level array from it.

var myArr = [1, 2, 3, [10, 11,[1321,3213,[321321, true], "ha"], 133], 4, 5];

The output should be:

mySecondArr = [10, 11, 133];

with the following code, the output will include the third grade and so on arrays

for(i = 0; i < myArr.length; i++){
    if (typeof(myArr[i]) == 'object'){

Thank you in advance!

You can filter by Array.isArray:

const findInnerArr = outerArr => outerArr.find(item => Array.isArray(item));
const myArr = [1, 2, 3, [10, 11,[1321,3213,[321321, true], "ha"], 133], 4, 5];
const output = findInnerArr(myArr)
  .filter(item => !Array.isArray(item));

Learn JavaScript Multidimensional Array By Examples, The following example defines a two-dimensional array named activities . To access an element of the multidimensional array, you first use square loop the inner array for (var j = 0; j < innerArrayLength; j++) { console.log('[' + i + ',' + j +  I want to generate a list of the second level of keys used. Each record does not contain all of the same keys. But I need to know what all of the keys are. array_keys() doesn't work, it only returns a list of numbers. Essentially the output Im looking for is: action, id, validate, Base, Ebase, Ftype, Qty, Type, Label, Unit

For more 2nd levels, you could filter by array and filter the inner arrays out and concat the result to a single array.

var array = [1, 2, 3, [10, 11, [1321, 3213, [321321, true], "ha"], 133], ['foo', 'bar', ['baz']], 4, 5],
    result = array
        .map(a => a.filter(b => !Array.isArray(b)))
        .reduce((r, a) => r.concat(a));


Indexed collections, let arr = [42] // Creates an array with only one element: // the number 42. let arr At the implementation level, JavaScript's arrays actually store their elements as standard forEach(function(element) { console.log(element) }) // first // second Using this characteristic of JavaScript arrays, multi-dimensional  Looping through multidimensional arrays. Just as with regular, single-dimensional arrays, you can use foreach to loop through multidimensional arrays. To do this, you need to create nested foreach loops — that is, one loop inside another: The outer loop reads each element in the top-level array.

@CertainPerformance answer looks much better, but still for your reference, this is your way.

var newArr = [];
for(i = 0; i < myArr.length; i++){
    if (typeof(myArr[i]) == 'object'){
        // second level found
        for(var j=0;j<myArr[i].length;j++){
            if(typeof(myArr[i][j]) != 'object'){

array_keys - Manual, If a search_value is specified, then only the keys for that value are returned. Searches the array for a given value and returns the first corresponding key if successful Here's a way to find all the keys from a multidimensional array while keeping the array structure. NOTE: If the sub element isn't an array, it will be ignore. Questions: Is it possible, in PHP, to flatten a (bi/multi)dimensional array without using recursion or references? I’m only interested in the values so the keys can be ignored, I’m thinking in the lines of array_map() and array_values().

Use Array.filter, Array.reduce and Array.isArray

let myArr = [1, 2, 3, [10, 11,[1321,3213,[321321, true], "ha"], 133], 4, 5, ['this', 'should', ['not'], 'be', 'part', 'of', 'result']];

/* 1. Get all the items that are array from myArr
** 2. Reduce that array with pushing non-Array into the result. */
let result = myArr.filter((a) => Array.isArray(a)).reduce((a,c) => [...a, ...c.filter((d) => !Array.isArray(d))], []);


array_values - Manual, Get all values from specific key in a multidimensional array into each level of the array to order (only the indexed) arrays and NOT flatten the whole thing. You can use ArrayHelper::merge() to merge two or more arrays into one recursively. If each array has an element with the same string key value, the latter will overwrite the former (different from array_merge_recursive()). Recursive merging will be conducted if both arrays have an element of array type and are having the same key.

Recursive mode get any level of the array

function getElementsAt(_array, level, currentLvl=1){
  if(level< 1) throw("level must be > 1");
  if(typeof _array === "undefined") throw("Array or level is undefined");

  hasSubLvl = _array.some(e=>{
    return e instanceof Array;
  if(currentLvl!== level){
  const __array = _array.filter(e =>{
      return e instanceof Array;
    return getElementsAt(__array, level, currentLvl+1);
    return !hasSubLvl ? _array : _array.filter(e =>{
    	return !(e instanceof Array);

const arr = [1, 2, 3, [10, 11,[1321,3213,[321321, true], "ha"], 133], 4, 5];
const myArr = getElementsAt(arr, 2);

console.log(myArr, "result");

MTS, Michigan Terminal System, Multidimensional arrays, however, will only be defined one-dimensionally for The formula for accessing a particular element of a two-dimensional array is "i+(j-​1)*n", where "i" represents the first subscript, "j" represents the second subscript,​  I need to initialize only the second level of a two-d array in cobol and preserve the filrst level without looping using a perform varying statement to the second level. Is there any way without using the subscript? Ex - 01 ws-item-count occurs 9 times. 05 ws-item-1 X(1). 05 ws-item-2 x(2). 05 ws-item-3 occurs 4 times. 10 ws-it3-a1 X(01).

Multidimensional array in JavaScript, How to force Input field to enter numbers only using JavaScript ? array then we need to create a multidimensional array by using another one-dimensional array. Removing elements in Multidimensional Array: We can use pop() methods to remove elements salary of 2nd person : 30000 salary of 4th person : 28000 In the last lesson I gave you a general overview of multi-dimensional arrays and how they are implemented in memory. Each programming language implements arrays somewhat differently, and the topic of this lesson is how to actually implement a two dimensional array in C.

Arrays in ColdFusion - a basic guide, Create a multi-dimensional array. ColdFusion supports dynamic multidimensional arrays. When you declare an  The JavaScript Array: Dense, Parallel and Multidimensional Dense Arrays The previous lesson featured JavaScript array syntax known as simple, or long array notation. While very easy to read and understand, writing a lot of arrays in long notation can become tiresome. Arrays can also be written in shorthand, producing what is known as a dense array.

Arrays - C++ Tutorials, registerlog in An array is a series of elements of the same type placed in contiguous 0 to 4, being 0 the first and 4 the last; In C++, the first element in an array is always For example, a bidimensional array can be imagined as a two-​dimensional With the only difference that with multidimensional arrays, the compiler  Quite Simple: [code]<?php // The Array $array = array( 'a' => array( 'a' => "a aaa", 'b' => "b bbb", 'c&#039; =&gt; &quot;c ccc&quot;, &#039;d&#039; =&gt; &quot;d ddd

  • what do you mean by second level array ? Can you give us some example ?
  • By second level array, he means the array at index 3 in myArr
  • by second level I've referred only to the elements in the first array to be found in the main array, example: [1,[2,3,[10],4],999] and the output should be displaying only [2, 3, 4] not [2, 3, [10], 4]
  • what should happens with more than one 2nd level arrays?
  • In case of multi-first level arrays, code will not work.