How to use es6 Spread(…) operator JavaScript
In this post we will give you information about How to use es6 Spread(…) operator JavaScript. Hear we will give you detail about How to use es6 Spread(…) operator JavaScriptAnd how to use it also give you demo for it if it is necessary.
Spread syntax(… three dots)
The spread syntax allows us to expand the arrays or strings where zero or more arguments are needed for the function calls or array literals or object literals.
Let’s see in practice
Combine arrays
const fruits = ['apples', 'apricots', 'avocados'];const veg = ['broccoli','corn','cucumber'];const vegplusfruits = [...fruits,...veg];console.log(vegplusfruits);// ['apples', 'apricots', 'avocados','broccoli','corn','cucumber']
In the above code, we combined two arrays into a single array by usingthe spread operator.
Function calls
We can use spread operator to pass the array of numbers as an function arguments.
Here is an example:
function sum (a,b,c,d,e,f,g,h){ return a+b+c+d+e+f+g+h;}const numbers = [1,2,3,4,5,6,7,8];console.log(sum(...numbers));//output -> 36Copying Objects
const user1 = { id: 1, name: "king",}const users = { ...user1, id: 2, name: "pop"}console.log(users);// {id: 1, name: "king", id:2, name: "pop"}Splitting the Strings
We can also use spread operator to split the single string into an array of strings.
const name = "opera";const array = [...name];console.log(array);// ["o", "p", "e", "r", "a"]
Hope this code and post will helped you for implement How to use es6 Spread(…) operator JavaScript. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs
PHP - I Can't get the $_POST Values on Ajax Request
In this post we will give you information about PHP - I Can't get the $_POST Values on Ajax Request. Hear we will give you detail about PHP - I Can't get the $_POST Values on Ajax RequestAnd how to use it also give you demo for it if it is necessary.
I want to share this posts with you because when i was working on native PHP and Ajax Post request(Specially AngularJS Post request) at that time i can't get Post value on form submit. That's why i would like to share you this post. I also want to tell you i was working on my Ubuntu 14.04. I did try lot but i can't get value.
At last find stuff to how to solve this issue, i did use "file_get_contents('php://input')" that way i could get POST value in json object and i also decode json value using "json_decode()". So let's try this way :
Example:
$post = file_get_contents('php://input');
$post = json_decode($post);
$sql = "INSERT INTO items (title) VALUES ('".$post->title."')";
$result = $mysqli->query($sql);
Hope this code and post will helped you for implement PHP - I Can't get the $_POST Values on Ajax Request. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs
