Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Column IN ('a', 'b', 'c')
- if (expression1 || expression2 || str === 'a' || str === 'b' || str === 'c') {
- // do something
- }
- if (expression1 || expression2 || {a:1, b:1, c:1}[str]) {
- // do something
- }
- var str = 'a',
- flag = false;
- switch (str) {
- case 'a':
- case 'b':
- case 'c':
- flag = true;
- default:
- }
- if (expression1 || expression2 || flag) {
- // do something
- }
- if (!Array.prototype.indexOf) {
- Array.prototype.indexOf = function(item) {
- var i = this.length;
- while (i--) {
- if (this[i] === item) return i;
- }
- }
- return -1;
- }
- if (['a', 'b', 'c'].indexOf(str) >= 0) {
- //do something
- }
- if (/Foo|Bar|Baz/.test(str)) {
- // ...
- }
- if (str.match("Foo|Bar|Baz")) {
- // ...
- }
- if (!Array.prototype.indexOf) {
- Array.prototype.indexOf = function(item) {
- var i = this.length;
- while (i--) {
- if (this[i] === item) return i;
- }
- return -1;
- }
- }
- >>> ("something" in {"a string":"", "somthing":"", "another string":""})
- false
- >>> ("something" in {"a string":"", "something":"", "another string":""})
- true
- >>> a = ["a string", "something", "another string"];
- >>> b = {};
- >>> for(var i=0; i<a.length;i++){b[a[i]]="";} /* Transform the array in a dict */
- >>> ("something" in b)
- true
- js> a = ['foo', 'bar', 'baz']
- foo,bar,baz
- js> a.indexOf('bar')
- 1
- js> a.indexOf('quux')
- -1
- function inList(psString, psList)
- {
- var laList = psList.split(',');
- var i = laList.length;
- while (i--) {
- if (laList[i] === psString) return true;
- }
- return false;
- }
- if (inList('Houston', 'LA,New York,Houston') {
- // THEN do something when your string is in the list
- }
- String.prototype.inList=function(list){
- return ( Array.apply(null, arguments).indexOf(this.toString()) != -1)
- }
- var x = 'abc';
- if (x.inList('aaa','bbb','abc') )
- console.log('yes');
- else
- console.log('no');
- String.prototype.inList=function(list){
- return ( list.indexOf(this.toString()) != -1)
- }
- var x = 'abc';
- if (x.inList(['aaa','bbb','abc']) )
- console.log('yes')
- var list = ['a', 'b', 'c'];
- if (list.include(str)) {
- // do stuff
- }
- function in_list(needle, hay)
- {
- var i, len;
- for (i = 0, len = hay.length; i < len; i++)
- {
- if (hay[i] == needle) { return true; }
- }
- return false;
- }
- var alist = ["test"];
- console.log(in_list("test", alist));
- if ('abcdefghij'.indexOf(str) >= 0) {
- //do something
- }
- // checking to see if var 'column' is in array ['a', 'b', 'c']
- if (column.isAmong(['a', 'b', 'c']) {
- // do something
- }
- Object.prototype.isAmong = function (MyArray){
- for (var a=0; a<MyArray.length; a++) {
- if (this === MyArray[a]) { return true;}
- }
- return false;
- }
- var str = 'some string with a',
- list = ['a', 'b', 'c'],
- rx = new RegExp(list.join('|'));
- rx.test(str);
- new RegExp(list.join('|')).text(str);
- var rx = new RegExp(list.join('|').concat('/i'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement