String Replace prototype method in javaScript

The String Replace method in the String prototype object of core javaScript comes in handy when it comes to most text search and replace tasks involving regular expressions. I just call the method off of the string, pass a regular expression as the first argument, and then a string, or method to generate a string as the second argument. The result is all instances of the pattern in the string being replaced with what I give as the second argument.

In order to really get into using replace it is important to get up to speed with regular expressions, a subject that can prove to be a little frustrating for many, but never the less when it does come to text search and replace tasks, and just matching tasks, regular expressions are a very powerful tool for doing so. With that said if you are not up to speed with regular expressions you might want to read up on them a little more before continuing.

Read More

String Match prototype method in javaScript

The String Match prototype method in javaScript can be used in combination with a regular expression to find one or more matches of a text pattern in a string. When making a regular expression instance a global flag can be used to get an array of all matches for a given text pattern rather than just the first match from left to right.

If you are still new to javaScript you might be using methods like the String index of method to find the index of a fixed text pattern in a string. This kind of method might work okay with fixed static patterns, where I am only interested in the first match from right to left, or if there is an instance of the pattern at all and thats it. However methods like that do have there limitations and in some cases it might be best to just get into regular expressions and methods like the string match method.
So this string match method is a great method that comes in handy, but it might not always be the best option when it comes to pattern matching tasks with javaScript and regular expressions. There is another option that might be a better choice when it comes to preforming a replacement task called the string replace method, but this post will focus more so on just matching. So then this will be a quick outline on the String match method in javaScript, with at least a few examples that should help with gaining greater knowledge of the use of this method as well as regular expressions in general in the process of doing so.

Read More

lodash template

The lodash template method is one way to go about creating and using templates to turn javaScript code into formatted html, and other formates as well for that matter. When making any kind of web based project with javaScript there will often be a need to take some data that is retrieve from a server for example and then present that data to the user in some way such as a canvas, or html view. The lodash template method is then one of a wide range of options for this sort of thing, and even if the lodash template method is not used a lot of other ways of doing this sort of thing work in a similar way.

There is a wide range of various projects and ideas for applications that come to mind where some kind of template system might be called for. One example of an application that came to mind for might right away is making a project that can be described as a static site generator. One of the aspects of a static site generator is that plain text, or markdown source files need to be converted into HTML and injected into an HTML page. However there are also all kinds of other application where a developer would want to go with at least some kine of template system.

This is where methods like the _.template method in lodash can be useful, However there are a whole lot of other options to be aware of when it comes to this sort of thing. There are other libraries and also frameworks such as VUEJS that might prove to be a better options for templates. These days there are also a whole lot of native options for templates built into javaScript itself, so lets take a look at some lodash template method examples, but also touch base on some other options for this sort of thing.

Read More

lodash over

In this post I will be taking a look at the lodash _.over method. This method can be used to create a function that calls one or more iteratee functions with all the arguments that are given to it via the function that is created with the lodash over method. The result that is returned is an array of values for each iteratee function that was passed when creating the method that was made with lodash over.

So in other words if you have two or more methods that all accept the same arguments in the same order the lodash over method can be used to create a single method that will create an array of values where each value is the result of each of these methods. So then it might prove useful in some situations so lets take a quick look at a few examples of this lodash over method.

Read More

lodash replace

The lodash the replace method can be used to quickly replace instances of a text pattern in a string with a static text value, or the result of a function call when it comes to generating some kind of replacement for each match. Although that pattern to look for can just be a simple string value, it might be best to just know how to use regular expressions to do the same with the String.replace method in native javaScript by itself.

In any case both methods are fairly useful for search and replace operations with text in javaScript. There is not just being knowledgeable with the features of the methods, but also regular expressions, and advanced options when using a method for each instance of a pattern. So in this post I will be writing bout some quick examples on this subject of search and replace of text that comes up a lot when working out a javaScript project.

Read More