Welcome to LinuxScrew

A site for Linux lovers worldwide. For newbies, system engineers, administrators, and everybody in between. We cover all things Linux, plus various programming languages, including Python, Javascript, and PHP.

View our featured tutorials and projects in the slider below or scroll down to see all recent articles.

How to Convert a USB Printer to Wireless with a Raspberry Pi
How to Use a Raspberry Pi for Digital Signage
The Worst Things You’ll Probably Google As a Programmer on Linux
How to Build a Raspberry Pi Internet Kiosk
Browsing the Internet on a 1989 Macintosh II with a Web Rendering Proxy
previous arrow
next arrow
Slider

The Best Way to Declare an Array in JavaScript

JavaScript Declare Array

There are several ways to declare an array in JavaScript. This article will show you which is the best. What is an Array? An array is a type of variable that holds an ordered list of values. Each value has a position in the array, called the index. The index can be used to access each value in the array. Indexes are integer values, which start counting from 0 (zero) for the first item in the array. The Literal Constructor – Declaring an Array using Square Brackets (The Best … Read more

Merge Arrays in JavaScript with concat() and push() [Examples]

JavaScript Join Merge Concatenate Arrays

This tutorial will show you the correct ways to merge two or more arrays in JavaScript with the concat method – and provide a warning about how not to merge arrays. Merging/Joining Arrays in JavaScript with the concat()* Method The concat() method exists with one purpose – to merge arrays. concat() Method Syntax array.concat(ARRAYS) Note that: array is the first array of the arrays to be joined ARRAYS should be a comma-separated list of arrays to be added to the first array They will be joined in the order of appearance concat() returns a new array – … Read more

How to Add one or More Items to an Array In JavaScript with push()

JavaScript Add Item to Array with push()

This tutorial will show you how to add items to a JavaScript array with the push() method – with code examples. You don’t want to have to re-declare an array every time you want to change the values in it – so let’s look at how to add items to existing arrays using the push() method. About JavaScript Arrays and Declaring Arrays I’ve covered the best way to declare Arrays in JavaScript in our article here. JavaScript Array push() Method Syntax A method is a function or procedure attached to an object. Calling that object’s … Read more

How to Randomize/Shuffle an Array in JavaScript [Examples]

JavaScript Randomize Shuffle Array

This article will show you a few ways, both easy and complex, to randomize/shuffle an array in JavaScript. The Quick and Dirty Way to Randomize an Array If you aren’t too concerned about the probabilities involved, this code is a quick way to randomize the contents of an array: // Function to return a shuffled copy of a given array function shuffle(array) { var shuffled = […array]; // Make a copy of the array to be shuffled so that the original is not altered by … Read more

How to Reverse an Array In JavaScript

JavaScript Reverse Array

This short article will show you how to reverse an array in the JavaScript programming language. What is an Array? An array is a type of variable that holds an ordered list of values. Each value has a position in the array, called the index – and can be accessed by using that index. As an array is ordered, the position matters. Values within arrays will be processed by loops and other data structures in order – so being able to reverse that order is beneficial. Reversing an … Read more

PHP: Process Each Item In An Array with array_map() [Examples]

PHP array_map

This article will show you how to process a PHP array using array_map() to run a function on each item in the array. Why use array_map()? Arrays store a sequence of values in a single variable. If you’re storing those values, you probably want to do something with them at some point. Say, for example, you had an array of numbers, and you wanted to calculate the square of each number to be stored in a new array. You could create an empty array, loop through the original array calculating … Read more

Categories PHP

Rounding Numbers Down with the PHP floor() Function, with Examples

PHP floor()

This short tutorial will cover how to use the PHP floor() function to round numbers DOWN – and provide some code examples. The PHP floor() function rounds a number down (and only down!) to the nearest integer. To round a number up to the nearest integer, use the ceil() function instead. To round a number normally, or for more options when rounding a number, use the round() function. PHP floor() Function Syntax The syntax for the PHP floor() function is as follows: floor($NUMBER) Note that: $NUMBER is the float or integer number you wish to perform the floor() operation on floor() will return a float type number regardless of … Read more

Categories PHP

TwisterOS For Raspberry Pi Does It All [Screenshots/Review]

twister os for raspberry pi

Here’s a screenshot-heavy review of Twister OS – a weird, kitchen-sink included Linux OS for Raspberry Pi with tools for emulation, gaming, and overclocking.  It even comes with Windows and macOS themes! Rather than make you read about what it does, I’ve included screenshots walking through the process of downloading, installing, and running Twister OS.  I’ve included some commentary, but the screenshots should let you decide for yourself whether you want to give this odd OS a go. First up, downloading and installing Twister OS … Read more

Rounding Numbers Up with the PHP ceil() Function, with Examples

PHP ceil()

This short tutorial will cover how to use the PHP ceil() function to round numbers UP – and provide some code examples. The PHP ceil() function rounds a number up (and only up!) to the nearest integer. To round a number down to the nearest integer, use the floor() function instead. To round a number normally, or for more options when rounding a number, use the round() function. PHP ceil() Function Syntax The syntax for the PHP ceil() function is as follows: ceil($NUMBER) Note that: $NUMBER is the float or integer number you wish to perform the ceil() operation on ceil() will return a float type number regardless of … Read more

Categories PHP

How to Use the PHP ‘while’ Loop, With Examples

PHP while

This tutorial will teach you how to use the while statement to build loops in the PHP programming language and show some examples. The while loop is the most straightforward kind of loop in PHP. The code inside the loop will execute for as long as the while condition is true. Change the condition, and the loop will exit. while loops are a fundamental part of PHP (and loops are an essential part of computer programming in general) – so it’s good to know how they work and what they can be … Read more

Categories PHP