array-push

findOneAndUpdate causing duplication problem

爷,独闯天下 提交于 2021-01-07 03:56:05
问题 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 'supporterOf' is the ref of UserModel and its type is 'ObjectId'. The issue i am facing here is that, 'some string' is being pushed twice under 'supporterOf' in the document. Can anyone tell me that how to push an array element inside the document? 回答1: I

how to use array_push for json_encode

可紊 提交于 2020-12-01 12:01:53
问题 I am iOS developer and I am making Webservices in PHP for getting JSON Response. Code which I wrote is: $result = mysqli_query($con,"SELECT * FROM wp_marketcatagories"); $data =array(); while($row = mysqli_fetch_array($result)) { $data[] = array_push($data, array('id' => $row['id'])); } $json = json_encode($data); echo $json; This is what I want in result: [{"id":"1"},{"id":"2"},{"id":"3"},{"id":"4"},{"id":"5"},{"id":"6"},{"id":"7"},{"id":"8"},{"id":"9"},{"id":"10"},{"id":"11"},{"id":"12"}]

ReactJS: How to prevent duplicate values in array.push?

允我心安 提交于 2020-04-18 07:12:49
问题 While selecting one option in the Select box at that time rest of the options are become multiple values. How can i prevent this duplicate values ? import Select from 'react-select'; const dataOptions = []; class App extends React.Component { constructor(props) { super(props); this.data = []; this.getData(); } getData = () => { api.request({url: `/getdata`}).then(res => res.map(el => this.data[el.id] = el.name)) } addData = () => { const { selectedId } = this.state; var datas = this.data;

ReactJS: How to prevent duplicate values in array.push?

允我心安 提交于 2020-04-18 07:12:07
问题 While selecting one option in the Select box at that time rest of the options are become multiple values. How can i prevent this duplicate values ? import Select from 'react-select'; const dataOptions = []; class App extends React.Component { constructor(props) { super(props); this.data = []; this.getData(); } getData = () => { api.request({url: `/getdata`}).then(res => res.map(el => this.data[el.id] = el.name)) } addData = () => { const { selectedId } = this.state; var datas = this.data;

PHP array_push() is overwriting existing array elements

谁都会走 提交于 2020-01-21 14:46:09
问题 I'm trying to push objects into an array to end up with an object array like this: [ {"recipient_name":"John D", "phone_number":"123456"}, {"recipient_name":"Doe J", "phone_number":"654321"}, {"recipient_name":"Jon Do", "phone_number":"112233"}, ] So I'm looping over a larger array to acquire the names and phone numbers and pushing them as an object to an array like this: $myLargerArray = pg_fetch_all($messageQuery); // This is my larger array $size = count($myLargerArray); for( $j = 0; $j <

php magic method to catch array_push

我只是一个虾纸丫 提交于 2020-01-02 08:55:32
问题 I am looking for a way to intercept the action in array_push, because when it will be retrieve it each value of the array has another info like: class ClassName { var $test = array(); function __set($attr, $value) { $this->$attr = 'My extra value'.$value; } function index(){ array_push($this->test, "some val"); array_push($this->test, "some other val"); print_r($this->test); } } $o = new ClassName(); $o->index(); And expected to get something like: Array ( [0] => My extra value some val [1] =

Associative array to Json [closed]

微笑、不失礼 提交于 2020-01-01 10:04:02
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I would like to be able to generate a json output in the following format: {"a":{"ax":1,"abx":2},"b":{"bax":1,"bbx":2},"c":3,"d":4,"e":5} Although I have found that the respective code is this: $arr = array('a' =

How to count unique value from object of array in javascript

爷,独闯天下 提交于 2019-12-31 04:51:07
问题 I want to calculate number of unique value and put that in new array. I have below array: [ { CategoryId: "b5c3f43f941c", CategoryName: "Category 1", CategoryColor: "cgreen" } { CategoryId: "9872cce5af92", CategoryName: "Category 2", CategoryColor: "purple" } { CategoryId: "b5c3f43f941c", CategoryName: "Category 1", CategoryColor: "cgreen" } ] I want new array with below result: [ { CategoryId: "b5c3f43f941c", count: 2, CategoryColor: "cgreen" } { CategoryId: "9872cce5af92", count: 1,

Removing a value from an array and moving them to another Array

丶灬走出姿态 提交于 2019-12-25 08:15:34
问题 I have a dropdown values from $scope.role from there I am able to select and remove the respective value from that dropdown and moving the values to $scope.multiRoles array . Which I am also displaying as tags .Which can be find in AddRole() Now when I click close button in the tag, I am calling removeRoles() , where I am splicing the array which I am selected. But I need to splice them and move them back to $scope.role . Till removing value it works fine , but I am unable to move it back to

Jquery push function [closed]

懵懂的女人 提交于 2019-12-24 00:33:56
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I'm working on samsung SDK and modifying a javascript app for smart tv. I stumbled upon this piece of code and I don't understand what if($('.menuButton'