# saveStrings Reference Error

**URL:** https://discourse.processing.org/t/savestrings-reference-error/26036
**Category:** Beginners
**Created:** [December 8, 2020, 5:49am UTC](https://discourse.processing.org/t/savestrings-reference-error/26036 "2020-12-08T05:49:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![CND](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@CND](https://discourse.processing.org/u/CND)
#### Post date: [December 8, 2020, 5:49am UTC](https://discourse.processing.org/t/savestrings-reference-error/26036/1 "2020-12-08T05:49:57Z")

</div>

The p5.js “saveStrings” Reference says:

let words = ‘apple bear cat dog’;  
let list = split(words, ’ '); \< \< ! ! This is wrong

iI needs to be… let list = words.split(’ ');

This threw me for a while before I looked hard.

---

<div class="post-metadata">

### Author: ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)
#### Post date: [December 8, 2020, 6:17am UTC](https://discourse.processing.org/t/savestrings-reference-error/26036/2 "2020-12-08T06:17:09Z")

</div>

“The split() function maps to String.split(), …”  
– [https://p5js.org/reference/#/p5/split](https://p5js.org/reference/#/p5/split)

It’ll work fine within the `setup()`, `draw()`, etc. functions. However, it won’t work in regular JavaScript, i.e. in the global scope of your sketch.

---

<div class="post-metadata">

### Author: ![CND](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@CND](https://discourse.processing.org/u/CND)
#### Post date: [December 12, 2020, 11:04pm UTC](https://discourse.processing.org/t/savestrings-reference-error/26036/3 "2020-12-12T23:04:53Z")

</div>

Why have it have 2 different syntaxes then?

---

<div class="post-metadata">

### Author: ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)
#### Post date: [December 13, 2020, 7:13am UTC](https://discourse.processing.org/t/savestrings-reference-error/26036/4 "2020-12-13T07:13:26Z")

</div>

The `String.split()` will work anywhere. It’s a standard JS method, so you could just stick to using that. I suspect that the p5.js developers added a `split()` function to replicate the [original Processing one](https://processing.org/reference/split_.html). Recall that p5.js is a JavaScript interpretation of _Java_ Processing.

Here’s more on the technical reasons why the `split()` function won’t work before `setup()` – [https://github.com/processing/p5.js/wiki/p5.js-overview#why-cant-i-assign-variables-using-p5-functions-and-variables-before-setup](https://github.com/processing/p5.js/wiki/p5.js-overview#why-cant-i-assign-variables-using-p5-functions-and-variables-before-setup)
