Skip to content

Instantly share code, notes, and snippets.

var provinces = [
{
'Name' : 'Ontario',
'Capital' : 'Toronto',
'Largest city' : 'Toronto'
},
{
'Name' : 'Quebec',
'Capital' : 'Quebec City',
'Largest city' : 'Montreal'
var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'];
function promiseFunction(url) {
return new Promise( function(resolve, reject){
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
resolve(xhr.responseText);
} else {
reject(xhr.statusText);
<?php
// Method 1
$json = file_get_contents('php://input');
$json = mb_convert_encoding($json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN');
$arr = json_decode($json,true);
echo "<pre>";
print_r($arr);
echo "</pre>";
// Define array
var products = ['apple', 'orange', 'banana'];
// Delete the product, but empty value remains in array
delete products[1];
// Remove the empty value from the array
products = products.filter(function (el) {
return el != null;
});