Questions tagged [array-map]

An array map function creates a new array by calling a callback function for each element of the provided input array. PHP: array_map( $callback, $input_array ), JavaScript: inputArray.map( callback ).

PHP's array_map() function accepts a callback function to run for each element in each array and an array to run through the callback function. It returns an array containing all the elements of arr1 after applying the callback function to each one.

array array_map ( callable $callback , array $array1 [, array $... ] )

array_map() — Applies the callback to the elements of the given arrays

Example:

function cube($n)
{
    return($n * $n * $n);
}
$a = array(1, 2, 3, 4, 5);
$b = array_map("cube", $a);
print_r($b);

Output:

Array
(
    [0] => 1
    [1] => 8
    [2] => 27
    [3] => 64
    [4] => 125
)
445 questions
-1
votes
1 answer

why is my google javascript array map deleting values?

I've got an array question for processing in google sheets. I'm trying to map a value from one sheet into another. Thanks for any help. I've got explanation and code below... PROBLEM: this gives me blank rows (policies2[i]). DESIRED OUTCOME: new…
Jason Torpy
  • 124
  • 14
-1
votes
3 answers

array.map not a function

When using array map method, the browser page is blank and in the console I receive an error: array.map not a function Although when I comment array.map before rendering the page and after page gets renderd I uncomment it and it works fine. const…
-1
votes
2 answers

How to combine 2 nested array of object values

How do I combine 2 nested arrays. There are 2 Array A and B const A = [ { "id": 0, "bp": true, "ba": "value1", "risk": [ { "id": 0.1, "rk": false, "title": "risk1", "control": [ { …
Ajay
  • 29
  • 7
-1
votes
1 answer

How to category with properties array object into sub-array object recursively?

I have this map function parameterize with dataObj which is from database execution return. function(dataObj){ obj.gateways = dataObj.map((item) => ({ gw_name: item.gw_name.toUpperCase(), pm_id:…
supunbatagoda
  • 73
  • 1
  • 10
-1
votes
4 answers

How to update an array of objects with data taken from the corresponding elements of another same-size array?

Say I have an array of objects as follows: data = [ { "id":34 }, { "id":35 }, { "id":36 }, { "id":37 } ] and another array as follows: myNumberArray = [1,2,3,4] They might be much larger, but the number of elements in both arrays will always…
Rahul
  • 29
  • 5
-1
votes
1 answer

How to get properties from an array_map of a array_map?

I've got several arrays which are like this : $myArray = [ [ 'value1' => 1, 'value2' => 2, 'value3' => 3, 'objectValue' => 'name' => 'toto' 'age' => 7, 'sexe' => 'M' ] [ 'value1' => 11, 'value2' =>…
Micka Bup
  • 391
  • 1
  • 9
-1
votes
1 answer

mapping of array in react

I am trying to map array in react but it is not working.How can i map the element.It shows TypeError: Cannot read properties of undefined (reading 'map') Thanks in advance Here is my code import {useCollection} from…
-1
votes
2 answers

How to fill an array with the same values X times and how to send the data correctly to a function?

I made a similar question related with arrays and maps but only half got answered which is why I'm making this one apart. I have this code (Only relevant info): const [libros, setLibros] = useState([]); const [cantidad, setCantidad] =…
ReactPotato
  • 1,262
  • 3
  • 26
  • 46
-1
votes
2 answers

Create an object of arrays with combining two arrays

https://stackblitz.com/edit/angular-enctgg-dvagm3 Problem statement : Am trying to patch the hours from arr2 to arr1 and then build the whole expected o/p as given below. I was trying with map. But not sure how to traverse through nested array. Note…
Lokesh
  • 59
  • 1
  • 11
-1
votes
1 answer

array_map not allow to pass object in use()

I am trying this: array_map(function($data) use ($this->id) { //code }, $arr); I'm getting an error that I can not pass an object to use(). What am I doing wrong? Thanks
Bhumi Shah
  • 9,323
  • 7
  • 63
  • 104
-1
votes
3 answers

How to make button work for the exact element clicked on rather than all element on rendered list

so I have a rendered list which was created from an array and each element in the list has a menu button which displays a modal for each element, now the problem is if i click on the button of index 0 instead of showing for only index 0 it show for…
Miriam
  • 45
  • 1
  • 6
-1
votes
1 answer

Replacing values of an array based on values from another array

I have the following array type export const images = [ { id: "000012", label: "night sky", cost: "35" }, { id: "000013", label: "country road", cost: "16" }, { id: "000014", label: "baseball game", cost: "12" }, { id: "000015", label:…
Butri
  • 339
  • 8
  • 22
-1
votes
1 answer

Map array dont show in table

I need map a array inside my page, and show the result in a table, but the content don't show up when I compiled the page. Can anyone help me? When I print in console the content of a var, this is here. But the info don't show up in the page import…
-1
votes
1 answer

Point to the mapped id in array

I'm using the map function to iterate through an array in the state. My code is: theList(){ return this.state.lists.map((list) => { return(
Somename
  • 3,376
  • 16
  • 42
  • 84
-1
votes
1 answer

Is there way to change values of array given from another array

$original array [['type_of_activity'=>'م.ص','total'=>'0'…