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
2
votes
10 answers

findOneAndUpdate causing duplication problem

I am having a problem in findOneAndUpdate in mongoose. The case is that i am updating a document by finding it. The query is as follows: UserModel.findOneAndUpdate({ individualId: 'some id' }, { $push: { supporterOf: 'some string' } }) The…
2
votes
3 answers

Laravel collection issue

I have to get the quantity of supplies for each supply by a certain supplier. I know that sounds weird but let me explain: I have a Supplier model which has many supplies and each supply has many stocks which have a quantity. So now I'm building a…
N. Kue
  • 77
  • 1
  • 7
2
votes
3 answers

How to merge two objects in PHP

I have problem when try to merge two array in PHP. For example I have: ( [k] => Array ( [aaaa] => 11 [bbb] => 22 ) ) And an array two follow: ( [k] => Array ( [ccc] => 333 …
pirpirim
  • 93
  • 2
  • 13
2
votes
3 answers

Put string between every array in an array - PHP

Lets say I have a text file with 9 sentences (it could be more! this is just an example) , then i read that file in my php and split it every 3 sentence and store it in a variable so it result in this array: $table = array( array( 'text…
2
votes
5 answers

PHP put values from CSV file into an array

I have a CSV file with two columns. The first is an ID number and the second is the number of products with that ID. The CSV can have multiple copies of the same ID, and what I need to do is merge these and add the number of products for each ID…
Edward144
  • 493
  • 6
  • 28
2
votes
3 answers

Add JSON Element To Multidimensional JSON Object PHP

I have a JSON object in a file called info.json that looks like this --> [ { "name": "level0", "items": [ { "name": "item1", "type": "type1" }, …
laroy
  • 163
  • 1
  • 1
  • 13
2
votes
7 answers

"push()" method returns the length of array instead of array (JavaScript)

I want to make a new array by adding an element to an existing array by "push()" method. This is the existing array: let arr = [{label: 1, value: 1}, {label: 2, value: 2}]; This is the element I want to add to the existing array: {label: 3, value:…
RamAlx
  • 6,976
  • 23
  • 58
  • 106
2
votes
2 answers

Foreach overwrites previous records in multidimensional array

I have a multidimensional array, and I want to show this array in tabular form like +------+-----+--------+-------+-------+ | Name | red | yellow | green | white | +------+-----+--------+-------+-------+ | abc | 8 | 2 | 4 | 0 | | xyz…
2
votes
2 answers

How to push an object to an array in php?

I am getting an xml from curl and then i am using simplexml_load_string to get values.In that i am getting all my product details and cart total.And I am getting product type from my database.But i don't know how to add that result (which is an…
piya
  • 205
  • 1
  • 6
  • 15
2
votes
3 answers

Passing array to hidden input and retrieve array with elements on different indexes

I have some fields that gets created automatically on click by javascript in the backend. Every field contains a delete button to remove the field, now I need to make sure the PHP code retrieves the deleted fields and delete them from the database.…
DaViDa
  • 641
  • 1
  • 8
  • 28
2
votes
4 answers

PHP - function return an array after array_push

Why is 'the array pushed element' not echoed? function dofoo1() { $array = array("1aaa", "2bbbb", "3cccc"); $count = '######'; $array1 = array_push($array, $count); return $array1; } $foo1 = dofoo1(); echo…
Latestarter
  • 39
  • 1
  • 7
2
votes
2 answers

Javascript push function into array in a loop

var calls = []; for (var y = 1; y <= 10; y++) { for (var x = 1; x <= 10; x++) { calls.push(function() { yooMe(x, y); }); } } for (var i in calls) { calls[i](); } var yooMe =…
Eric Tang
  • 207
  • 1
  • 4
  • 10
2
votes
1 answer

array_push not adding 2nd item after page refresh

I understand that array_push is not adding a 2nd item because when the page refreshes after adding another item the original one goes away and get's replaced by the most recent entry from the text box. I am trying to achieve this tactic of trying to…
mistkaes
  • 399
  • 1
  • 2
  • 21
2
votes
5 answers

Warning: array_push() expects parameter 1 to be array, string given

I am getting Warning: array_push() expects parameter 1 to be array, string given in ... for array_push() on this piece of code. The warning occurs in the first push, how do I fix this? $url = $_SERVER['QUERY_STRING']; $chunk =…
2
votes
1 answer

How to insert element in a PHP array one by one using AJAX?

I want add the elements in array one by one from php file that i have set as ajax url. i that file the id is changed each time and i want to add these all id in one array. here is my JS code: $("body").on("click",".ins-img", function() { var…
sangam
  • 171
  • 2
  • 4
  • 13