๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ json-parser
JSON Parser Online to parse JSON
JSON Example with all data types including JSON Array. ... JSON.Parse() is javascript method for parsing JSON which converts to JavaScript objects.
๐ŸŒ
Vite
vite.dev โ€บ guide โ€บ features
Features | Vite
Vite automatically rewrites code-split dynamic import calls with a preload step so that when A is requested, C is fetched in parallel:
Discussions

Split array into two different arrays using functional JavaScript - Stack Overflow
I was wondering what would be the best way to split an array into two different arrays using JavaScript, but to keep it in the realms of functional programming. Let's say that the two arrays shoul... More on stackoverflow.com
๐ŸŒ stackoverflow.com
javascript - Split array into chunks - Stack Overflow
Let's say that I have an Javascript array looking as following: ["Element 1","Element 2","Element 3",...]; // with close to a hundred elements. What approach would be appropriate to chunk (split... More on stackoverflow.com
๐ŸŒ stackoverflow.com
how can I split an array into multiple arrays based on a property?

I would seriously reconsider that data structure if you can help it, but here is a solution:

const obj = {}

for (let i = 0; i < arr.length; i++) {
  const category = arr[i].category || arr[i].name

  if (!obj.hasOwnProperty(category)) {
    obj[category] = []
  }

  obj[category].push(arr[i])
}

const result = Object.values(obj)
More on reddit.com
๐ŸŒ r/learnjavascript
13
8
August 9, 2021
Iโ€™m trying to split up an image into smaller chunks using JavaScript (on server)
Often, it is simplest to not reinvent the wheel . Or if you want to avoid importing a whole library for one function, you can always look to see how the library did it for inspiration. Alternatively, there's always stack overflow with examples on chunking arrays and strings . Often, the array methods work on strings anyway. Nothing that I found online helped You've done a great job of defining exactly what your problem is (which is often the hardest part!), but it might be a good idea to work on your searching skills. A google search like "chunk array javascript" or "chunk string javascript" has multiple solutions (see: stack overflow above) and even entire tutorials on exactly what you're asking for. More on reddit.com
๐ŸŒ r/learnprogramming
5
2
March 17, 2024
๐ŸŒ
Alpine.js
alpinejs.dev โ€บ start-here
Start Here โ€” Alpine.js
The first thing I'd like to point out is that x-data now has a lot more going on in it than before. To make it easier to write and read, we've split it up into multiple lines in our HTML. This is completely optional and we'll talk more in a bit about how to avoid this problem altogether, but for now, we'll keep all of this JavaScript directly in the HTML.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ String โ€บ split
String.prototype.split() - JavaScript | MDN
The split() method of String values takes a pattern and divides this string into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_splice.asp
JavaScript Array splice() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_slice_array.asp
JavaScript Array slice() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_split.asp
JavaScript String split() Method
The split() method splits a string into an array of substrings.
Find elsewhere
๐ŸŒ
ConvertCSV
convertcsv.com โ€บ json-to-csv.htm
JSON To CSV Converter
It can also be a single object of name/value pairs or a single object with a single property with an array of name/value pairs. It can also be in JSONLines/MongoDb format with each JSON record on separate lines. You can also identify the array using Javascript notation.
๐ŸŒ
ReactHustle
reacthustle.com โ€บ blog โ€บ how-to-split-a-javascript-array-by-index
How to Split a Javascript Array by Index | ReactHustle
Hello, hustler! In this tutorial, you'll learn how to split a javascript array by index by using Array.prototype.slice method.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ slice
Array.prototype.slice() - JavaScript | MDN
The slice() method of Array instances returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.
Top answer
1 of 7
16

collateBy

I just shared a similar answer here

I like this solution better because it abstracts away the collation but allows you to control how items are collated using a higher-order function.

Notice how we don't say anything about animal.length or < 4 or animals[0].push inside collateBy. This procedure has no knowledge of the kind of data you might be collating.

// generic collation procedure
const collateBy = f => g => xs => {
  return xs.reduce((m,x) => {
    let v = f(x)
    return m.set(v, g(m.get(v), x))
  }, new Map())
}

// custom collator
const collateByStrLen4 =
  // collate by length > 4 using array concatenation for like elements
  // note i'm using `[]` as the "seed" value for the empty collation
  collateBy (x=> x.length > 4) ((a=[],b)=> [...a,b])

// sample data
const arr = ['horse','elephant','dog','crocodile','cat']

// get collation
let collation = collateByStrLen4 (arr)

// output specific collation keys
console.log('greater than 4', collation.get(true))
console.log('not greater than 4', collation.get(false))

// output entire collation
console.log('all entries', Array.from(collation.entries()))

Check out that other answer I posted to see other usage varieties. It's a pretty handy procedure.


bifilter

This is another solution that captures both out outputs of a filter function, instead of throwing away filtered values like Array.prototype.filter does.

This is basically what your reduce implementation does but it is abstracted into a generic, parameterized procedure. It does not use Array.prototype.push but in the body of a closure, localized mutation is generally accepted as OK.

const bifilter = (f,xs) => {
  return xs.reduce(([T,F], x, i, arr)=> {
    if (f(x, i, arr) === false)
      return [T, [...F,x]]
    else
      return [[...T,x] ,F]
  }, [[],[]])
}

const arr = ['horse','elephant','dog','crocodile','cat']

let [truthy,falsy] = bifilter(x=> x.length > 4, arr)
console.log('greater than 4', truthy)
console.log('not greater than 4', falsy)

Though it might be a little more straightforward, it's not nearly as powerful as collateBy. Either way, pick whichever one you like, adapt it to meet your needs if necessary, and have fun !


If this is your own app, go nuts and add it to Array.prototype

// attach to Array.prototype if this is your own app
// do NOT do this if this is part of a lib that others will inherit
Array.prototype.bifilter = function(f) {
  return bifilter(f,this)
}
2 of 7
8

The function you are trying to build is usually known as partition and can be found under that name in many libraries, such as underscore.js. (As far as I know its not a builtin method)

var threeFourArr = _.partition(animals, function(x){ return x.length < 4 });

I don't like this too much, because it seems that the data structure is going to give a bit of problems, seeing that it is an array of arrays

Well, that is the only way to have a function in Javascript that returns two different values. It looks a bit better if you can use destructuring assignment (an ES6 feature):

var [smalls, bigs] = _.partition(animals, function(x){ return x.length < 4 });

Look at it as returning a pair of arrays instead of returning an array of arrays. "Array of arrays" suggests that you may have a variable number of arrays.

I've managed to look at similar questions online as well as Stack Overflow, but many of these break the idea of immutability by using push() or they have very unreadable implementations, which in my opinion breaks the expressiveness of functional programming.

Mutability is not a problem if you localize it inside a single function. From the outside its just as immutable as before and sometimes using some mutability will be more idiomatic than trying to do everything in a purely functional manner. If I had to code a partition function from scratch I would write something along these lines:

function partition(xs, pred){
   var trues = [];
   var falses = [];
   xs.forEach(function(x){
       if(pred(x)){
           trues.push(x);
       }else{
           falses.push(x);
       }
   });
   return [trues, falses];
}
๐ŸŒ
Python Tutor
pythontutor.com โ€บ visualize.html
Python Tutor code visualizer: Visualize code in Python, JavaScript, C, C++, and Java
Free online compiler and visual debugger for Python, Java, C, C++, and JavaScript. Step-by-step visualization with AI tutoring.
๐ŸŒ
Slate
slate.com โ€บ technology โ€บ 2026 โ€บ 02 โ€บ winter-snow-cold-when-will-it-end.html
When will winter end? In some parts of the U.S., itโ€™s been the coldest winter in 20 years.
1 week ago - But fear not! The cycle is nearing its end, with a dramatic finish. By Cohenโ€™s estimates, the polar vortex will actually split within the next two weeks. Our polar vortex is being pummeled by a โ€œwrestling tag team,โ€ says Cohen. The two fighters: repeated stretches, which weaken the polar vortex and cause it to snap more easily (think a rubber band), and also the calendar.
๐ŸŒ
Kurims
kurims.kyoto-u.ac.jp โ€บ ~ooura โ€บ fft.html
FFT Package 1-dim / 2-dim
This is a package to calculate Discrete Fourier/Cosine/Sine Transforms of 1-dimensional sequences of length 2^N. This package contains C and Fortran FFT codes ยท The same routines are in each C and Fortran file. Simple versions use no work area, but fast versions use work areas.
๐ŸŒ
Saurabhmisra
saurabhmisra.dev โ€บ sql-server-convert-delimited-string-into-rows
4 ways to convert delimited string data into individual rows in SQL Server | Saurabh Misra
July 5, 2021 - So we'll create a function that will take in a comma separated string and return a set of rows of the split values.
๐ŸŒ
VisuAlgo
visualgo.net โ€บ en โ€บ sorting
Sorting (Bubble, Selection, Insertion, Merge, Quick, Counting, Radix) - VisuAlgo
When the array A is already in ascending order, e.g., A = [5, 18, 23, 39, 44, 50], Quick Sort will set p = A[0] = 5, and will return m = 0, thereby making S1 region empty and S2 region: Everything else other than the pivot (N-1 items). ... The first partition takes O(N) time, splits A into 0, 1, N-1 items, then recurse right.
๐ŸŒ
Medium
medium.com โ€บ @python-javascript-php-html-css โ€บ effectively-dividing-an-array-of-items-into-segments-depending-on-byte-length-in-javascript-7ecbb4199baa
Effectively Dividing an Array of Items into Segments Depending on Byte Length in JavaScript
October 8, 2024 - The scripts provided in the previous examples are designed to solve a common problem in JavaScript: splitting an array of objects into smaller chunks based on the byte size of each chunk. This is particularly useful when working with systems that have strict memory or payload size limits, such as APIs or database inserts.
๐ŸŒ
Node.js
nodejs.org โ€บ en โ€บ blog โ€บ release โ€บ v24.14.0
Node.js โ€” Node.js 24.14.0 (LTS)
2 weeks ago - [8c25489d63] - test: split test-fs-watch-ignore-* (Luigi Pinca) #61494
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ split-an-array-into-chunks-in-javascript
Split an Array into Chunks in JavaScript - GeeksforGeeks
July 11, 2025 - It automatically divides the array, returning an array of these chunks, with the last chunk containing the remaining elements if the array can't be evenly split.