Did you ever squint at two columns of data and examine them row by row to compare the values? Excel can do all that hard work for you in three different ways. User in this case, while code required to convert JSON String to Java object is just two lines in fromJson(String json) method. These rules also apply to the switch statement. You can use the jQuery $. In this article you will learn how to compare two dates using C# and the jQuery Datepicker. C# string method returns a result that provides us information that string is greater than or less than the other, or that the two strings are equal. alert (search_for_string_in_array ('two', my_array)); Simply pass the value to search for and the array to the function and it will tell you whether the string exists as a part of an array value or not. The selector for the element to compare the current values Example: Makes "field" required to be the same as #other. Let me explain you with an example. html file and include the jQuery file before head tag closed. What is the easiet way to use the Form Plugin?. Although ASP. json file, or within JavaScript as an object or a string. If you have a long string like "Bobby Susan Tracy Jack Phil Yannis" and want to store each name separately, you can specify the space character " " and have the split. ToPrimitive(A) attempts to convert its object argument to a primitive value, by attempting to invoke varying sequences of A. The odds are pretty high that it’s really a string. The output then displays any differences. Using i ndexOf(). Any argument value that is less than 0 or greater than stringName. In equalsIgnoreCase() method, two strings are considered equal if they are of the same length and corresponding characters in the two strings are equal ignoring case. What if you need to search through sales records to find all transactions on, or before, or after a certain date, or between two dates? The actual dates may (and probably will) be different for each search, so you allow the user to input the search dates, and then do the comparison for each record. This article explains the basic difference between these two. The beforeSerialize function is invoked with two arguments: the jQuery object for the form, and the Options Object passed into ajaxForm/ajaxSubmit. The jQuery library simplifies syntax and helps ease navigation and handle events and asynchronous applications. name and returning either -1, 1, or 0 accordingly to sort, exactly the formula used inexplicitly by the sort () method without any function passed in. C# - Check string contains substring or not: Here, we will learn how we can whether a string contains substring or not using string. When we are starting to write automation tests for application ajax based we ask ourself:. slice() extracts a part of a string and returns the extracted part in a new string. how to check undefined in jquery, how to check if a variable is undefined in javascript, check value is empty or not in jquery, check null in jquery,jquery check for null or empty string ItSolutionStuff. parseDate(for mat, string) to turn your date strings into a JavaScript Date object, which you can then compare using the standard < and >. compatibility : ie9+ Effort to put appearance via css (easier to skin / override) Touch friendly, mouse drag, with a big thanks to Hammerjs:) Responsive. Home » Jquery » jQuery :contains selector to search for multiple contains selector to search for multiple strings How do you compare two version Strings in. We've barely scratched the surface of objects, but you now know the basics you'll need to know to work with objects as you learn jQuery. Sharepoint Date compare using Jquery. Take fortune API for example, you can call the API using Javascript/AJax so that the message is displayed on the browser. String "tablesorter-noSort" Class name added to element inside header. Re: How to change date format of a value using JQuery? Sep 14, 2011 12:27 AM | bruce (sqlwork. The selector for the element to compare the current values Example: Makes "field" required to be the same as #other. The data source sorts the data items client-side unless the serverSorting option is set to true. how can i do it using jquery?. Have a look at the following example where two strings are compared in an if statement: An example of Python compare strings with == Two string variables are created which is followed by using the if statement. How to Convert JS Object to JSON String in JQuery/Javascript? How to check whether a value is numeric or not using jQuery ? How to animate div width and height on mouse hover using jQuery ? How to change the background image using jQuery ? jQuery UI | Spinner to select numeric data; How to append an element in two seconds using jQuery ?. While it does the job well, you must note that the function is actually intended to return the index at which a given substring is found, and -1 when there's no match. Sort of like this:. It compares the value of the string object (or a substring) to the sequence of characters specified by its arguments. The function can return an individual data item or an array of data items to be inserted into the resulting set. For this solution, we will use three methods: the String. SQL - How to check if a string has uppercase / lowercase characters Hello, When you need to compare two strings in SQL to check if this string contains uppercase or lowercase values it is always a problem, because in sql " ExTremeDev. jQuery sort() method will sort the strings based on ASCII values. name and returning either -1, 1, or 0 accordingly to sort, exactly the formula used inexplicitly by the sort () method without any function passed in. css( PropertyName, PropertyValue ); Here you can pass PropertyName as a JavaScript string and based on its value, PropertyValue could be string or integer. Thursday, February 7, 2013 jQuery jQuery Codes Find code to convert String to float or double using jQuery. How do i find the difference between two dates using jquery Description : If you want know How do i find the difference between two dates using jquery, just follow the below steps to get the result. } – Map of strings or objects which will be serialized with the paramSerializer and appended as GET parameters. 6: the browser normally takes around 30ms for either method. To secure a proper result, variables should be converted to the proper type before comparison: age = Number(age);. If a function, the function is invoked for each element, with that element set as the function context (this). jQuery Forum. example usage1: if a is animal && (and) b is man, print something. The Taconite Plugin is essentially a port of that project's parser functionality. i've made the assumption that names are unique. JavaScript String Split Function The ability to split up a string into separate chunks has been supported in many programming languages, and it is available in JavaScript as well. NET Forums / General ASP. The comparison between values is strict. compare() is a public member function of string class. The method returns 0 if both the strings are equal, -1 if string 1 is sorted before string 2 and 1 if string 2 is sorted before string 1. Visit this page to see our current promotions, on sale flooring and special financing offers on our superior flooring products. HTML Source. With this class it is possible to either convert a String to an int, or an int to a String. jQuery Images Compare. In this tutorial, you will learn how you can get all the checkboxes values using JQuery. , in the expression 5 == '5' , the string on the right is converted to Number before the comparison is made. Notice that the value stored can be any JavaScript object and in this example it is probably better to think of storing two string objects rather two string literals. Strings in JavaScript are primitive data types and immutable, which means they are unchanging. But don’t just take my word for it: both Prototype’s evalJSON and JQuery’s parseJSON use eval…so you might be using eval in your code even as you argue against it :-). Read about search and other string methods. inArray( 5 + 5 jQuery in Action Bear. Return value is 0 if both dates are equal. To sum two variables, they need to be converted to a number. Let me explain you with an example. com | © Demo Source and Support. It trims both at the beginning and the end of the string. json file, or within JavaScript as an object or a string. names (String|Function) Specifies the class name, or a space-delimited string of names, to be toggled. To secure a proper result, variables should be converted to the proper type before comparison: age = Number(age);. text() - Click on the heading to see the text displayed in the. The current content of a div and the new content, loaded from a (currently) static page. This tutorial helps you how to convert images into base 64 string using jQuery/javascript. match() function. Let's see the three ways with suitable examples. Posted in: Using jQuery Core > Frequently Asked Questions How do I get the text value of a selected option? Select elements typically have two values that you want to access. This application loops though each line in the text boxes and compares the contents. Add the dpDate marker class to your datepicker fields or specify dpDate in the rules section of your validate call. The elements are taken from either the beginning or the end of the source array, string or number, as specified by the value and sign (positive or negative) of limit. // Compare two List and display common elements Using jQuery to Delete a Row in a Table by just Clicking on it I showed you how to delete a Table Row. Result c# string lowercase example The ToLower function or method converts all the uppercase characters in the string to lowercase characters, If string contains some lowercase letters or characters it ignores them. Compare Images and Multimedia. When it comes to CSS the first thing that you need to do is identify the HTML part that is affected which is the selector and then identify what needs to be changed this forms the declarations. This article covers the topic of string trimming in JavaScript. String array. WordPress will automatically load jQuery for you when your plugins require it these days. This short post demonstrates the setUrlEncodedKey and getUrlEncodedKey that do. If the array lengths are unequal, you can work on the principles of the merge sort algorithm, and get a list of items that are common across both arrays. jQuery’s documentation says: jquery. Oracle provides regexp_substr function, which comes handy for this scenario. The Equality Operator ( ==) is the comparison operator and the Equals() method compares the contents of a string. 2 A few main points about arrays in Java: 3 Why using Arrays 4 Example of Java int array 5 An example of a string array 6 An example of …. Feature: New method jQuery. This example slices out a portion of a string from position 7 to position 12 (13-1):. Java String equalsIgnoreCase() method is used to compare a string with the method argument object, ignoring case considerations. Converting Strings to Number in Javascript: Pitfalls. In this article, I'll explain how to solve freeCodeCamp's "Repeat a string repeat a string" challenge. Converting String to Number for calculation. By David Walsh on October 20, 2011. For Ex: 1433097000000 1434479400000 Here i have to find the days between these two by jquery For Ex: 15/06/2015 - 22/06/2015 If it is more than 5 days, I want to get from is 15/06/2016, to is 19/06/2015. There are some differences between the two methods - return values and others as you compare objects/strings. Wednesday, February 6, 2013 jQuery jQuery Codes Find code to convert String to Integer using jQuery. my-class');. b) Strings are a primitive type in Java that overloads the + operator for concatenation. var currentId = $('#element'). Sort of like this:. It will allow you to create elements by passing a selector. These are two quick ways to check if one String contains other String, Character or Substring or not, which is very common programming question in Java interviews, along with how to compare two String in Java or how to split String in Java. parseHTML uses native methods to convert the string to a set of DOM nodes, which can then be inserted into the document. You can listen to change event to add some of your logic. actual cost is greater than budget cost. There are the three ways to compare the strings. How to display all items or values in an array using loop in jQuery. This method works well when you are building a string from a small number of component strings. Did you ever squint at two columns of data and examine them row by row to compare the values? Excel can do all that hard work for you in three different ways. slice() extracts a part of a string and returns the extracted part in a new string. escapeSelector( selector ) method takes a selector string and escapes any character that has a special meaning in a CSS selector. javascript,jquery,date I have two long dates value. Posted in: Using jQuery Core > Frequently Asked Questions How do I get the text value of a selected option? Select elements typically have two values that you want to access. Just create date object of the dates and then using comparison operator you can compare the dates. To determine whether a string is a valid representation of a specified numeric type, use the static TryParse method that is implemented by all primitive numeric types and also by types such as DateTime and IPAddress. Previous: Find the absolute position of an element using jQuery. C# Substring() Method. 5 framework or greater) and traditional for loop also work in lower version of. You can even write your own combine() method which can use System. To compare collections which may contain same values but in different positions we can use custom logic. ), it cannot work, since 'string' does not equal /regex/, even though the XOR operation would be expected to return false. These methods do render all trailing or leading text (even if that's just whitespace). reverse() method and the Array. Though using equals() to compare object is considere d Java best practice, c omparing Enum using == is better than using equals. C# string compare method is used to compare two strings, you have option to ingnore or compare case of the string. Note: The strcmp() function is binary-safe and case-sensitive. In basic jQuery, you'll mainly use objects to provide configuration options. So, it is better to have all uppercase letters or all lower case letters for strings in arrays. To prevent trailing/leading whitespace from being converted to text nodes you can pass the HTML string through jQuery. How to get selenium to wait for ajax response? As we all like modern application BUT modern applications are not easy to test. By default, the data items are not sorted. Each grain is separate—it is an element in a collection. C# string method returns a result that provides us information that string is greater than or less than the other, or that the two strings are equal. No true, since jQuery always returns an object with length 0. 3 and later. inArray( 5 + 5 jQuery in Action Bear. Get code examples like "how to append select option in jquery" instantly right from your google search results with the Grepper Chrome Extension. Creating dates from String (parsing to Date) Now, let's explore another common issue when we work with JavaScript Dates. It’s easy to apply any CSS property using jQuery method css( PropertyName, PropertyValue ). There are times when we need to calculate the difference between two dates in Java. String Comparison in java. Comparing Strings in PHP. In my collection I have foo, foo,bar. There are many ways to convert a String to a Number. Javascript does not provide any direct way to compare time. This method takes an Jon String which represent a User object in JSON format and convert it into Java User object. To determine whether a string is a valid representation of a specified numeric type, use the static TryParse method that is implemented by all primitive numeric types and also by types such as DateTime and IPAddress. escapeSelector( selector ) method takes a selector string and escapes any character that has a special meaning in a CSS selector. That said, it makes a lot of sense to use eval when it is necessary to parse response strings from your server into JSON or other JavaScript. I want to compare the value from an input field, with a string. params – {Object. It can be done with two Javascript functions substr() and substring() which can be easily used in jQuery. In addition to the comparison operators, which can be used on string values, the concatenation operator (+) concatenates two string values together, returning another string that is the union of the two operand strings. unobtrusive file that takes all data- attributes and works with them. In this tutorial, I show How you can check whether an Array already contains a specific value or not. Hi, I need to compare two textbox values using jquery. Accept Reject Read More. Using getTime() method. If element exists: length > 0, and condition is true. parseJSON()) before parse it with jQuery $. I think you will love mootools 2. Two Json Strings that might have different values at some point of time , and i want to know if is it possible to compare. Tip: This function is similar to the strncmp() function, with the difference that you can specify the number of characters from each string to be used in the comparison with strncmp(). This includes both code snippets embedded in the card text and code that is included as a file attachment. NET integrated AJAX technology by introducing the is the UpdatePanel server control, jQuery offers an alternative, and more versatile, way of doing it and a great deal more besides. Javascript does not provide any direct way to compare time. If an object and a string are compared, attempt to convert the object to a string and then check for equality. But it doesn't work, when the loaded content is the same as the current content, it still loads the new content When I view the content vars, they really are equal (I used the JS alert). If the return value is 1 or greater than 0 then the first string is greater than the second. Please do not try to build a JSON string manually; use your language's built-in JSON function or libraries to do it for you. This involves repeating a string a certain number of times. Following list is an example of. But as jQuery is built on top of JavaScript so you can use them with jQuery as well. If you need to modify the query string from the client before submitting the page it's nice to have a couple of small routines to do this easily. Step 1: Take two Textboxes to receive input, one label to show output message and Button. What is the easiet way to use the Form Plugin?. Hi, I need to compare two arrays using javascript or jQuery and then get distinct values from each of them, like for example: javascript - How to compare two arrays using Javascript and get unmacthed elements?. ready Comparing Two Json Strings Using jQuery. Bash also provides ways of comparing string and this is the topic of this tutorial. For jQuery collections, use. This is helpful when we need to turn several strings into one comma-delimited string. The result of the above comparison will return false. String array. how can i do it using jquery?. Learn JavaScript and jQuery a nicer way This full-color book adopts a visual approach to teaching JavaScript & jQuery, showing you how to make web pages more interactive and interfaces more intuitive through the use of inspiring code examples, infographics, and photography. DataTables Table plug-in for jQuery Advanced tables, instantly. For example, if you only require to check whether two strings are the same (ignoring case). C# string compare method is used to compare two strings, you have option to ingnore or compare case of the string. It iterates over each matched element in the collection and performs a callback on that object. Other array-like objects are also supported (e. text() is safe and backward. You can't just add a string of markup to a fragment, you have to add an HTML node. This is a very easy and simple program written in jQuery to calculate any two numbers. By default selenium actively scrolls to the element that needs to perform actions but you might end up having issues most of them happen on Firefox but even in Google. NET Developer / Compare two strings in Jquery Compare two strings in Jquery [Answered] RSS 3 replies. Specify the target date as either the actual date (as a string in the current date format or a Date object), as 'today', or as another datepicker field (as a jQuery selector, jQuery collection, or DOM element). sort Array|Object. Equals(Str1. In equalsIgnoreCase() method, two strings are considered equal if they are of the same length and corresponding characters in the two strings are equal ignoring case. date_diff() – This function returns the difference between two DateTime objects. Scanner; public class TwoString { public static void main(String[] args) { Scanner sc = new Scanner(System. Have a look at the following example where two strings are compared in an if statement: An example of Python compare strings with == Two string variables are created which is followed by using the if statement. I want to compare the value from an input field, with a string. All rights reserved. Learn JavaScript and jQuery a nicer way This full-color book adopts a visual approach to teaching JavaScript & jQuery, showing you how to make web pages more interactive and interfaces more intuitive through the use of inspiring code examples, infographics, and photography. Now copy the below HTML code and add to the index. Once We client the Submit Hyperlink, JQuery will make a POST request to the WCF Service, which will add the data to our Users List. If strings are same, it evaluates as True, otherwise False. Learn JavaScript and jQuery a nicer way This full-color book adopts a visual approach to teaching JavaScript & jQuery, showing you how to make web pages more interactive and interfaces more intuitive through the use of inspiring code examples, infographics, and photography. slice() extracts a part of a string and returns the extracted part in a new string. @psalmi: You’re right it’s a little clunky. now i want to calculate difference between to dates in NO OF DAYS. Does the Form Plugin have any dependencies on other plugins? No. Have a look at the following example where two strings are compared in an if statement: An example of Python compare strings with == Two string variables are created which is followed by using the if statement. The java compare two string is based on the Unicode value of each character in the strings. 5+, if you decorate your web service class as a [ScriptService], then you don't have to do any of that mess. The approach is fast and simple, but falls apart pretty quickly for all but the most basic of arrays. I want to compare the value from an input field, with a string. In the above table, ToNumber(A) attempts to convert its argument to a number before comparison. jQuery Forum Move this topic Forum : Getting Started Using jQuery Using jQuery Plugins Using jQuery UI Developing jQuery Core Developing jQuery Plugins Developing jQuery UI QUnit and Testing About the jQuery Forum jQuery Conferences jQuery Mobile Developing jQuery Mobile. The current content of a div and the new content, loaded from a (currently) static page. Pattern matching using string methods: Use the "search" string method for case insensitive search. Please correct the errors and try again. For this purpose, I was thinking to do a differential search between the original JSON & the modified JSON and save only the changes. 5, if writing a custom filterFormatter function, you'll need to call an additional function after initialization has completed so the "filterInit" event isn't triggered prematurely. When comparing two strings, "2" will be greater than "12", because (alphabetically) 1 is less than 2. I will try to describe some of them and give few advices to deal with them. ValidationSummary(true, "Account creation was unsuccessful. js we create a Line Chart with database MS SQL server connectivity via jQuery ajax call in Asp. html page in your browser and execute the program to see the output. For this purpose, I was thinking to do a differential search between the original JSON & the modified JSON and save only the changes. The Compare method returns three possible values as int: If the return value is 0 then both strings are same. In this post, we’ll learn how to sort an HTML table using jQuery without using any jQuery plugins. Hi, I need to compare two textbox values using jquery. This involves repeating a string a certain number of times. How to Parse String to Float in Java | Convert Float to String in Java - 3 Examples float and double are two data type which is used to store floating point values in Java and we often need to convert String to float in Java and sometimes even a Float object or float primitive to String. NET Forums / General ASP. how can i do search of the entire arrayList by the person name and add the new person if it doesn't exist. compare to compare the position of two nodes. Add the dpDate marker class to your datepicker fields or specify dpDate in the rules section of your validate call. You and use the jQuery file by linking a copy of it to your web page. Below are the four method for removing duplicate entries from an array, all does same task with the different - 2 ways using list contain (internally using linq) method, collection distinct extension method (internally using linq need. Earlier I had posted about jQuery solution to replace string, substring, trim string and about all string functions, And In this post, see jQuery/JavaScript split function in action with example. Please help. In after trigger, I've to compare old and new values of these strings and extract two lists and create records of some other object; One list should have those values which are newly added. The Flickr JSON is a little confusing, and it doesn’t provide a direct link to the thumbnail version of our photos, so we’ll have to use some trickery on our end to get to it, which we’ll cover in just a moment. String Comparison in java. All APIs are implemented and running on this VPS. But don’t just take my word for it: both Prototype’s evalJSON and JQuery’s parseJSON use eval…so you might be using eval in your code even as you argue against it :-). Meaning whatever the user has changed, track those things to later be able to save it. Note: The strcmp() function is binary-safe and case-sensitive. split() method, the Array. var currentId = $('#element'). If element exists: length > 0, and condition is true. In other cases you may be combining strings in a loop, where you don't know how many source strings you are combining, and the actual number of source strings may be quite large. You can achieve this easily using jQuery’s attr() method:. Here is the summary: Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions ; Two numbers are strictly equal when they are numerically equal (have the same number value). } – Map of strings or objects which will be serialized with the paramSerializer and appended as GET parameters. We often create applications where we need to compare a few things just as in the case of entering a password and re-enter the password. Download a copy of jQuery from the Downloading jQuery page and store the jquery. I got a requirement to compare the data of two similar tables existing in two different schemas. To compare this approach of retrieving data back from CRM Service using this method of invoking the REST Endpoint via JSON against SOAP XML Messages, the two script examples below illustrate how to retrieve the Account Number for a selected Account in CRM – the first generating the XML Messages manually and the second using jQuery functions. C# Corner Annual Conference 2020 Tickets on Sale Now x Top 10 Social Media Influencers. height() : it measure the height of the element/container excluding applied padding, margin and border-width. Any argument value that is less than 0 or greater than stringName. Let's see the three ways with suitable examples. The user can force close it on day 2 and launch subsequently without issues. If you've a JSON format set, like a particular API endpoint returning JSON, and you want to compare the same structure for a possible change in values, yo. cssIgnoreRow: String "tablesorter-ignoreRow" Class name to add to a table header row if you want all cells within this row to be ignored (v2. A jQuery plugin that converts a date object to a supplied format. 建議使用 equals() 以下是範例. Therefore, if I compare the first value with the second then the condition is false because firts value == second value. Equals(Str1,Str2) returns True. The function can return an individual data item or an array of data items to be inserted into the resulting set. bash compare strings unix shell. The CompareStringEx function compares two strings by looking for linguistic differences per the specified language rules. SharePoint workaround to create a list view based on a comparison between 2 list fields - e. Face Detection with jQuery Building Resilient Systems on AWS : Learn how to design and implement a resilient, highly available, fault-tolerant infrastructure on AWS. IsTrue (text. grep() method removes items from an array as necessary so that all remaining items pass a provided test. The latter is hardly ever useful in JavaScript, which is why you can usually forget about String as a constructor and concentrate on its role as converting to string. trim() function. Comparing Strings in PHP. There are lot of changes in Java API from Java 1. ParseExact() methods for converting a string-based date to a System. how can i do it using jquery?. Or at least, get to the next issue. Migrate jQuery and FullCalendar solution built using Script Editor web part to SharePoint Framework. The type conversion does not take place when the comparison is === or !== as this involves comparing the type as well as the value. compare to compare the position of two nodes. jQuery Images Compare. How to remove unmatched row in html table using jquery jquery,html I have two tables. User in this case, while code required to convert JSON String to Java object is just two lines in fromJson(String json) method. Re: How to change date format of a value using JQuery? Sep 14, 2011 12:27 AM | bruce (sqlwork. Convert image to base64. Converting Strings to Number in Javascript: Pitfalls. By comparison, accessing text values (innerText, textContent) will yield raw strings, meaning they’re unsafe and could contains XSS. SharePoint News, Views and "How To's" How To setup a SharePoint view filter to compare 2 list fields. Two of the most common ways to calculate age from a birth date in Excel are to use the DATEDIF function and to use standard arithmetic operators on date fields. Return value is less than 0, if Date is before the date argument. jQuery Check if String Contains Specific Word in JavaScript or how to use jQuery to check particular word in string in JavaScript or jQuery to check if string contains specific word in JavaScript jQuery Check if String Contains Specific Word in JavaScript - ASP. i've made the assumption that names are unique. The locale is based on the language settings of the browser. there are several things work with dates, it's like carbon. Two Json Strings that might have different values at some point of time , and i want to know if is it possible to compare. Please help. Earlier I had posted about jQuery solution to replace string, substring, trim string and about all string functions, And In this post, see jQuery/JavaScript split function in action with example. C# string compare method is used to compare two strings, you have option to ingnore or compare case of the string. The CompareStringEx() Win32 functions compare two character strings in a case-sensitive or case-insensitive manner, respectively, following the sorting rules and standards that are defined for the specified user locale. String Variable - Declare and Initialize with Combined Strings. My initial strategy was to convert them to JSON and compare the JSON strings. IsTrue (text. One of the ways is using the extended slice and the other is reversed method with the join() for reversing a string. [TestMethod] public void TestStringContains {var text = "This is a sample string"; Assert. Check if two arrays or objects are equal with JavaScript Yesterday, we looked at a way to tell if two arrays are equal with JavaScript. There are some differences between the two methods - return values and others as you compare objects/strings. Did you ever squint at two columns of data and examine them row by row to compare the values? Excel can do all that hard work for you in three different ways. js or update the src attribute. When setting the dates you can provide one value, two values (for a range), or mutliple values in an array. If you are also using jQuery ui, in particular datepicker, you can use $. I got a requirement to compare the data of two similar tables existing in two different schemas. The function can return an individual data item or an array of data items to be inserted into the resulting set. Comparing Strings in PHP. I will try to describe some of them and give few advices to deal with them. See the Pen jquery-practical-exercise-27 by w3resource (@w3resource) on CodePen. While it does the job well, you must note that the function is actually intended to return the index at which a given substring is found, and -1 when there's no match. This method is necessary because it's not possible to compare strings using the equality operator (==). parse() or $. If an array is returned, the elements inside the array are inserted into the set. And as you might have just discovered, in JavaScript you can certainly compare two string (done so alphabetically).