Questions tagged [array-push]

array-push refers to the javascript Array.prototype.push() method. The push() method adds one or more elements to the end of an array and returns the new length of the array.

refers to the javascript Array.prototype.push() method.

The push() method adds one or more elements to the end of an array and returns the new length of that array. developer

Example

var a = []; //or new Array()
var i = a.push('foo', 'bar');
console.log(i, a); 

the console will display the values

2 ["foo", "bar"]

The counterpart to push() is pop(), which removes the last item from an array.

Documentation

382 questions
0
votes
1 answer

php array_push behavior

I am new to php and am not sure why this isn't working. Could someone help me? Thanks! My code is below: if (!$this->_in_multinested_array($over_time, $request_year)) { $temp = array('name'=>$request_year, 'children'=>array()); …
Mars J
  • 902
  • 3
  • 15
  • 23
0
votes
5 answers

how do I keep a certain number of elements in an array?

How do I keep a certain number of elements in an array? function test($var) { if(is_array($_SESSION['myarray']) { array_push($_SESSION['myarray'], $var); } } test("hello"); I just want to keep 10 elements in array $a. So when I…
TigerTiger
  • 10,590
  • 15
  • 57
  • 72
0
votes
2 answers

array_push giving comma-seperated array - php

I'm quite new to PHP and coming from a Java background. So here it goes: I have this code: $selected = array(); foreach($this->getSelectedOptions() AS $array) { array_push($selected, $array['value']); } var_dump($selected); getSelectedOptions()…
Krt_Malta
  • 9,265
  • 18
  • 53
  • 91
-1
votes
1 answer

How to push new array in react native object

i have following array [{ "games1": [{ "playername": "1" }] }, { "games2": [{ "playername": "1" }, { "playername": "2" } ] …
Mohit Jain
  • 15
  • 3
-1
votes
7 answers

Add array value after echoed

I'm creating a web app where I want to include JavaScript files with all file sources in an array, but I can't do that. Header.php
user19690494
-1
votes
2 answers

Trying to make an array out of an object entries using 'push' to an empty array. Simply won't work

I have this function on a React component, that fetches data from a AWS API and returns it on an Object. I tried transforming the data received in the object in an array. The function that fetches the data is listUsers. Then i used the push method.…
Henrique Monteiro
  • 107
  • 1
  • 1
  • 9
-1
votes
1 answer

Why can't I add a key and value when PHP array_key_exists is FALSE?

I am simply trying to add a set of keys and values to an array if and only if they are not already in the array. I need to add d1 thru d20 when they are not already in the array, Here is my code. print_r($demos_keys) Array ( [0] => d01 [1]…
David Weisser
  • 117
  • 1
  • 10
-1
votes
1 answer

Append several one-dimentional arrays to a one-dimentional array with array_push

I want to add data from a numeric, one-dimensional array to an existing one-dimensional total array, like in https://www.php.net/manual/de/function.array-push.php My solution creates a two-dimentional array. Where is my logic…
dh1sbg
  • 15
  • 5
-1
votes
2 answers

How to add strings to an existing object without replacing it in a loop?

I want to add $datasigned string value to the existing $data values, what should I do? public function index(Request $request){ $data = Apidata::select('file')->where('nim','=',$request->nim)->get(); foreach($data as $berkas){ $url =…
Aditya Pratama
  • 657
  • 1
  • 8
  • 21
-1
votes
3 answers

PHP: If value exists in array, assign a new value and push all values to a new array

I want to check if JSON array in the databse has a value. Every value corresponds to a WordPress category ID. (For example, "elevator" = 120) If it does exist, I need to push it to an array called $features so that I can later run a script that…
-1
votes
1 answer

Array push to a key giving null value in php

So I am taking some input from json that is the userid. Then I am trying to find its friends and their blogs and its respective comments. Obviously the comments will be more than one. So whenever I am doing a array push to those comments to a key…
sumit735
  • 3
  • 1
  • 3
-1
votes
1 answer

how to push data in array in typescript

I want to create a dynamic menu bar by fetching data from two collections (supcat and cat) then combining the two to create a new array which i will access on page load for menu but the push() is not working. ngOnInit()…
-1
votes
2 answers

how to merge 2 arrays in angular 7 typescript

In angular 7 projects for a specific component I have to get data from wp site and dotnet site via api. From wp api I am getting data as(console log data ): (2) [{…}, {…}] 0: {title: "Henk WJ Ovink", description: "Special Envoy for International…
samjhana joshi
  • 1,995
  • 4
  • 35
  • 69
-1
votes
2 answers

How to push key value of element to array_push using PHP

I have created empty array and want to push all values and its key to the new created array but I am getting error array_push() expects at least 2 parameters I know array_push needs two parameter and here I am passing only one but what I ant is all…
Anonymous
  • 1,074
  • 3
  • 13
  • 37
-1
votes
2 answers

Error When Pushing Key/Value Pair Array with array_push

I'm trying to push a key/value pair to an array like so: $holders_array = array(); foreach ($holders as $holder) { array_push($holders_array, "date" => $holder['date'], "holders" => $holder['holders']); } But I am getting the error: Parse…
ShittyDeveloper
  • 117
  • 1
  • 8