In_array function not working


#1

Hello,

I have tried “in_array” function in script as well as template7 but not working right know.

//Example
if(in_array(‘van’, [‘Kevin’, ‘van’, ‘Zonneveld’])){
alert(‘TEST’);
}


#2

What is “in_array” function?


#3

Thanks for reply @nolimits4web

It’s jquery function “jQuery.inArray()”.

I want to use the jquery inarray function for template7


#4
Template7.registerHelper('inArray',function(val,arr){
  return arr.indexOf(val) !== -1;
});

var obj={
  val:'van',
  arr:['Kevin','van','Zonneveld']
};

Template7.compile('{{#this}}{{inArray val arr}}{{/this}}')(obj);

#5
Template7.registerHelper('inArray',function(val,arr,callback){
  return callback(arr.indexOf(val) !== -1);
});

var obj={
  val:'van',
  arr:['Kevin','van','Zonneveld'],
  callback:function(result){
    console.log('the result is',result);
  }
};

Template7.compile('{{#this}}{{inArray val arr callback}}{{/this}}')(obj);