Home » Search results for 'javascript object'

How to Remove Duplicates From an Array in JavaScript [Examples]

Javascript Remove Duplicates from Array

Being able to remove duplicates from (or de-duplicate) an array is a useful thing to be able to do. Here’s how it’s done. What is an Array? In programming, an array is a type of variable that can hold other values, or references to other variables, in a list at a certain position. Arrays are vital to building any application – allowing you to store a list of variables or values of any length in a single variable – ready to be iterated over, processed, … Read more

Home » Search results for 'javascript object'

JavaScript – Pausing Execution or Sleep Function Equivalent

Javascript Pause/Sleep

JavaScript does not include a sleep function to pause execution – but you can achieve the same effect with this simple code. Unlike shell scripts and PHP, JavaScript does not include a built-in function to pause execution for a set amount of time. In other programming languages, this is usually called the sleep function. Unfortunately, JavaScript doesn’t have an equivalent function, but we can build one ourselves! JavaScript Promises Modern versions of JavaScript include support for new functionality called promises. Put simply; a promise is a new … Read more

Home » Search results for 'javascript object'

How to Create and Use Enums in JavaScript (Not TypeScript)

JavaScript Enum

This article will show you how to create and consume Enums in JavaScript. Unfortunately, javaScript does not include native support for Enums, but you can add comparable functionality yourself. Note that TypeScript, a language that builds on JavaScript, does include support for Enums natively. So we’re only looking at plain JavaScript here – not TypeScript. What is an Enum? An Enum (Enumerated Type) is a data structure containing multiple values. Each value is assigned to an identifier – and can be accessed by that identifier. Enums contain pre-defined constants … Read more

Home » Search results for 'javascript object'

Generate Random Numbers and Strings in JavaScript [Examples]

Javascript Random String Number

This guide will show you how to quickly and easily generate random numbers and strings in the JavaScript programming language. Generating random values is a common and important task when programming almost any kind of application of moderate complexity. Random strings and numbers are used to generate unique identifiers (e.g., for the short URLs in URL shortening services), for identifying unique records in a database, and (most importantly) are frequently used to determine the behavior of gameplay elements in video games (for example, simulating a … Read more

Home » Search results for 'javascript object'

JavaScript String split() Method, With Examples

JavaScript Split Method

Want to split a string up into several smaller strings using JavaScript? This is the article for you. The JavaScript string.split() method will split up a string and return an array of strings. The string will be split at the position noted by a specified character. Here’s how to use it. JavaScript string.split() Syntax A method is a function or procedure available to run from an object or variable which will be run using the value from that variable. The split() method is available on any string typed variable. Here’s the … Read more

Home » Search results for 'javascript object'

What is ‘undefined’ in JavaScript?

JavaScript Undefined

This short article will explain what ‘undefined’ means in JavaScript – as both a type and a variable value. Creating a Variable with an undefined value To create a variable with an undefined value, it simply needs to be declared with no assigned value, for example: var myVariable; console.log(myVariable); If the above code is executed, undefined is logged as the value of myVariable as no value was assigned. undefined is a Type of Variable undefined is one of the primitive variable types in JavaScript. A variable type describes what a variable can be used for (for … Read more

Home » Search results for 'javascript object'

Check Type of Variable in JavaScript with typeof [Examples]

JavaScript typeof Operator

This article will explain JavaScript variable types and how to find the type of a variable using the typeof operator. The typeof operator is quite similar to the instanceof operator – but they do not function the same way.  instanceof returns TRUE or FALSE when checking if a variable is of a certain type, whereas typeof returns the name of the type. What are Types? The type of a variable determines what it can or can’t do. It determines what value the variable may take and … Read more

Home » Search results for 'javascript object'

How to use the JavaScript trim Method, with Examples

JavaScript trim

This easy tutorial will show you how to use the JavaScript string trim() method and give some example usage. The trim()* method is available to any string type variable in JavaScript. It removes any white space (spaces, tabs, newlines) found at the beginning and the end of the string. Why is this useful? Sometimes you wind up with a bunch of un-needed white space padding your strings – often from the end-user hammering the space key when a space isn’t required. Unnecessary white space can also occur after splitting … Read more

Home » Search results for 'javascript object'

How to Get the Last Item in a JavaScript Array [Quick Tip]

JavaScript - Get last item in array

This quick article will show you how to get the last item in an array in the JavaScript programming language. Arrays and Array Indexes in JavaScript Arrays are an ordered list of items. Each item in the array has a numerical index that defines its permission in the array. The first index is index 0 (indexes start counting at 0, not 1!), so the last index is the array’s length; subtract 1. Getting the Last Item in an Array So, to get the last item in an array, we just … Read more

Home » Search results for 'javascript object'

How to Filter Arrays in JavaScript, With Examples

Javascript: filter arrays

We’ve covered arrays in JavaScript pretty extensively on LinuxScrew. This article will show you how to use the filter method – with easy-to-follow examples. JavaScript Arrays Arrays are a type of variable that holds a list of other values or variables. They’re one of the fundamentals of computer programming. These lists contain items at positions (called indexes). These items can be anything – numbers, strings, complex objects – whatever you want to store. Arrays are super useful. You might use them to store the rows in a … Read more