From d41202d921f42d7967632944c0274213f016c7d5 Mon Sep 17 00:00:00 2001 From: David Boyne Date: Tue, 27 Aug 2024 16:47:29 +0100 Subject: [PATCH] feat(docs): adding learn by for Wing --- .../version-latest/10-structs.md | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 example_versioned_docs/version-latest/10-structs.md diff --git a/example_versioned_docs/version-latest/10-structs.md b/example_versioned_docs/version-latest/10-structs.md new file mode 100644 index 00000000..cca74be8 --- /dev/null +++ b/example_versioned_docs/version-latest/10-structs.md @@ -0,0 +1,47 @@ +--- +title: Structs +id: structs +slug: /structs +sidebar_label: 10. Structs +description: Using arrays with Wing +keywords: [Wing language, example] +--- + +Structs are loosely modeled after typed JSON literals in JavaScript. + +```js playground example title="main.w" +let main = () => { + + let a = MutArray[1, 2, 3]; + + log("{a[0]}, {a[1]}, {a[2]}"); + + a[2] = 4; + + log("mutated value: {a[2]}"); + log("len: {a.length}"); + + let data = MutArray[1, 2, 3]; + let twoD = MutArray>[data]; + + for array in twoD { + for item in array { + log(item * 10); + } + } + +} + +``` + +```bash title="Wing console output" +# Run locally with wing console +wing it + +1, 2, 3 +mutated value: 4 +len: 3 +10 +20 +30 +``` \ No newline at end of file