• Categories
  • Recent
  • Tags
  • Popular
  • Solved
  • Unsolved
  • Users
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Darkly)
  • No Skin
Collapse
brainCloud Forums
H

helliyum

@helliyum
About
Posts
2
Topics
1
Groups
0
Followers
0
Following
0

Topics

  • H

    How to add to an array in Cloud Code?

    Scheduled Pinned Locked Moved Cloud Code function push cloud code script array cloud code
    2
    0 Votes
    2 Posts
    386 Views
    H

    I posted this almost 13 days ago with zero answers, so I took some time to look through a bunch of documentation and did a ton of trial and error. Please Braincloud for the love of god add this to your API.

    Rhino does not handle Arrays the way that other coding languages do.

    I figured it out, unlike most arrays that return an array after you call push- Rhino returns the new length. So if you call push, don't set it's value.

    var copyArray = []; //I assume this line tells it to be an array for (var i = 0; i < postResult.data..length; i++) { copyArray[i] = postResult.data[i]; //arrays do not behave like .Net arrays, you can change length without initializing, so you just set each index to the index of the array you're copying } copyArray.push(variableToAdd); //Do NOT set this as the value of your array, the push method returns an int (length of array) NOT an array! //you probably dont need to call push at all to add to the array as shown in the for loop above if you already know your length or want a specific length

    Then just set your value to the variable, like this

    var entityData = { "variableName": copyArray }; //No need to call Array(copyArray) or any of the prototype. slice stuff. If you call Array() you'll just nest the array a second time.

    Use this page for further info on functions you can do with arrays.

  • Login

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • Solved
  • Unsolved
  • Users