0

I want to use this jquery function inside my jaggery file:

$.inArray(value, array)

What is the most efficient way of doing it? Jquery is already imported in the file using a <script> tag. I think using require() function to again get jquery would be inefficient.

Riyafa Abdul Hameed
  • 7,417
  • 6
  • 40
  • 55
  • Why don't you just use `array.indexOf(value)`? It's already built into JS. – jfriend00 Jan 26 '16 at 05:19
  • That method is not available in jaggery. It is not hard to write a custom function. But I would like to know how to efficiently use jquery in jaggery – Riyafa Abdul Hameed Jan 26 '16 at 05:42
  • Seriously? There's a Javascript environment that is so behind the times that it doesn't have `Array.prototype.indexOf()`? You could write your own in about five lines of code. There's a polyfill [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf#Polyfill). – jfriend00 Jan 26 '16 at 06:17

1 Answers1

0

You cannot use jQuery in JaggeryJs. Jaggery is designed to run at the server side(Internally uses Rhino Engine). Unless there's a jQuery library for server side scripting you won't be able to do this.

As an alternative you could do something like this;

[1, 2, 3].includes(2);     // true
[1, 2, 3].includes(4);     // false
[1, 2, 3].includes(3, 3);  // false
Govinnage Rasika Perera
  • 2,134
  • 1
  • 21
  • 33