From 73d2a1b63642df88f3964b6cdc660eb738f37c98 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 12 Jun 2020 10:20:22 -0700 Subject: [PATCH] Demonstrate another way to update an array --- .../04-updating-arrays-and-objects/text.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/site/content/tutorial/02-reactivity/04-updating-arrays-and-objects/text.md b/site/content/tutorial/02-reactivity/04-updating-arrays-and-objects/text.md index 82e4c91d35..a33e0171b0 100644 --- a/site/content/tutorial/02-reactivity/04-updating-arrays-and-objects/text.md +++ b/site/content/tutorial/02-reactivity/04-updating-arrays-and-objects/text.md @@ -13,7 +13,15 @@ function addNumber() { } ``` -But there's a more idiomatic solution: +You can also do this in one line: + +```js +function addNumber() { + numbers = numbers.push(numbers.length + 1) && numbers; +} +``` + +Or for conciseness, use the spread operator if not in code that needs to be optimized: ```js function addNumber() {