Global array/object in helpers?

    niceArray: [
      index: 1,
      title: 'hello',
      price: '5-20',
      chance: Session.get('something')
    'click .doit': function (e) {
      var blabla = niceArray[( - 1];

Okey. so im trying to grab niceArray in But it seems like its not global.

If i create the array (not sure if it is called array or object) outside the helpers. It becomes global and i can use it anywhere. But the problem with this is that it doesnt get updated to the client if i change something in it.

How can i solve this problem?


put it in the settings.json under the public key


Do i create a settings.json file? I guess

What is public key?


Just do it this way:

var niceArray = [ .... values ... ];{
  'click .doit': function (e) {
    var blabla = niceArray[( - 1];

I don’t think that’s valid syntax for Meteor helpers. Helpers are expected to be functions that return something to be used in a template via {{helperName}}.


Yeah, that works. But if i change something in the niceArray. It doesnt get updated directly to the client. How can i solve this?


Make niceArray reactive, like so:

Session.set('myNameSpace/niceArray', [
    index: 1,
    title: 'hello',
    price: '5-20',
    chance: Session.get('something')
  { ... }

If you’re going to use Session, introduce some sort of namespacing or grouping in your variable names to keep things clean. Session.set('group/specificName', ...).


PS: This feels like niceArray should be a MongoDB collection.


Thank you a lot for your help. I appreciate it!

Im not going to add more stuff to the array, just change a variable slightly. So i think this is enough for now. But ill think about it as i continue developing


No problem!

Also keep in mind, if you don’t want to store temporary data such as this in MongoDB, you can use a temporary unmanaged collection:

NiceArray = new Mongo.Collection(null);

This collection not stored on the server, and is discarded as soon as the client leaves the website.

Session.set('coolNamespace/pikachu', [
      index: 1,
      title: 'Narnia',
      price: '5-20',
      chance: (60 * Session.get('thisDoesntUpdate'))

    thisPrintsToTheClient: Session.get('coolNamespace/pikachu')
    'click .doit': function (e) {

      var stuff = Session.get('coolNamespace/pikachu')[( - 1];

It doesnt seem to update directly to the site still :confused:

{{#each thisPrintsToTheClient}}
    <div class="popcorn">
      <div data-id="{{index}}" class="doit">Well</div>
      <div class="chans">{{chance}}%</div>
      <div class="valuta">{{price}}kr</div>
      <div class="title">{{title}}</div>


Helpers should return functions.

  thisPrintsToTheClient: function () {
    return Session.get('coolNamespace/pikachu')


Hmm, it still doesnt update directly.

It does update if i make the server restart (by making a small change and saving)

But it doesnt change instantly, without a server-restart :<


Try this:

    'click .doit': function (e) {

      var stuff = Session.get('coolNamespace/pikachu')[(
      var chance = stuff.chance;

I’m using this though to grab the chance from the object to I dont think that solution is possible?

I’m new at meteor so im sorry if i am slow


I got it working! ^^

var chance = (stuff.chanceMultiplier) * Session.get(‘level’);


Good! No need to apologize, there’s a lot to learn about Meteor. I’m still learning daily. :smile:


You can use ReactiveArray package for that too, and you will declare it as var.