Day: May 8, 2017

Javascript: 二维数组转一维数组(合并数组) Convert a 2D array to a 1D array

Here, I’m trying to convert arrToConvert to a 1D array. var arrToConvert = [[0,0,1],[2,3,3],[4,4,5]]; console.log(get1DArray(arrToConvert)); //print the converted array function get1DArray(2dArr){ //concatenate each element of the input into a 1D array, and return the output //what would be the best way to implement this function? }  … Read More

JavaScript: JSON对象 (JSON格式, JSON.stringify()和JSON.parse()的用法)

JSON格式 JSON格式(JavaScript Object Notation的缩写)是一种用于数据交换的文本格式,2001年由Douglas Crockford提出,目的是取代繁琐笨重的XML格式。 相比XML格式,JSON格式有两个显著的优点:书写简单,一目了然;符合JavaScript原生语法,可以由解释引擎直接处理,不用另外添加解析代码。所以,JSON迅速被接受,已经成为各大网站交换数据的标准格式,并被写入ECMAScript 5,成为标准的一部分。 简单说,每个JSON对象,就是一个值。要么是简单类型的值,要么是复合类型的值,但是只能是一个值,不能是两个或更多的值。这就是说,每个JSON文档只能… Read More