0
我得到了countries.json
,我按照規範將其分成4列顯示。使用lodash將數組均勻分塊
我正在尋找一種解決方案,將數組元素均勻分佈到所有四個數組中。
樣品的jsfiddlehttps://jsfiddle.net/5tkjLs7b/
如果我從JSON數據刪除一個國家,我將結束-了6個陣列。但預期只有4個陣列。
此外,數據應均勻分佈。
例如:我得到63項* 4陣列+ 3項* 1陣列全部 country.json。
var countries = [
{"name": "Afghanistan", "code": "AF"},
{"name": "Åland Islands", "code": "AX"},
{"name": "Albania", "code": "AL"},
{"name": "Algeria", "code": "DZ"},
{"name": "American Samoa", "code": "AS"},
{"name": "AndorrA", "code": "AD"},
{"name": "Angola", "code": "AO"},
{"name": "Anguilla", "code": "AI"},
{"name": "Antarctica", "code": "AQ"},
{"name": "Antigua and Barbuda", "code": "AG"},
{"name": "Argentina", "code": "AR"},
{"name": "Armenia", "code": "AM"}];
chunkedCountries = _.chunk(countries, countries.length/4)
console.log(chunkedCountries);