JavaScript Objects – A Friendly Introduction Pt.2

JavaScript objects can be difficult to learn, especially for beginners. In this tutorial you will learn how to loop through JavaScript objects with for...in loop, Object.keys()Object.values()Object.entries() and Object.getOwnPropertyNames(). You will also learn how to freeze objects and about some gotchas.

JavaScript Objects – A Friendly Introduction Part 1.

Looping over JavaScript objects

In previous part, you’ve learned about the basics of JavaScript objects. What if you want to know what keys and properties specific object contains? In JavaScript, there are multiple built-in ways to find this out. The most popular are for...in loop, Object.keys()Object.values()Object.entries() and Object.getOwnPropertyNames().

For…in loop

The first one, for...in loop, loops over all the properties of given object and returns keys. When you use bracket notation, obj[key], the for...in loop will retrieve the value of current key. The syntax of for...in loop is very easy. In a fact, it is even easier than syntax of for loop.

When you use for...in loop you have to specify two things. The first one is a variable. On each iteration, this variables holds current key name, or current property. When you log this variable you will see what key, or property, is currently accessible in the loop. For this variable, you choose any name you want.

What you need to remember is to use the same variable in the loop, when you want to get current key, or property, or its value. The second thing you have to specify is the object you want to loop over. Lastly, you need to put the in keyword between the variable and object you want to loop over, i.e. for (let someKey in someObject) {}.

// For...in loop example
// Create simple object
const specterObj = {
  id: 's5903',
  name: 'Specter',
  active: true
}

// Use for...in loop to iterate over specterObj
for (let objKey in specterObj) {
  // Log current key, temporarily stored in objKey variable
  console.log(`Current key is: ${objKey}.`)

  // Log the value of current key, using bracket notation
  console.log(`Current value is: ${specterObj[objKey]}.`)
}
// 'Current key is: id.'
// 'Current value is: s5903.'
// 'Current key is: name.'
// 'Current value is: Specter.'
// 'Current key is: active.'
// 'Current value is: true.'

Side note: Don’t confuse for...in loop with for...of loop. These two loops look very similar. There is a variable for current property and something to loop through. Aside to that, there two differences. First, there is of keyword, instead of in. The second difference is in that “something” to loop through.

The for...in loop was designed to be used to loop through properties of JavaScript objects. The for...of loop, on the other hand, was designed to be used to loop through iterable objects. What are iterable objects? In JavaScript, iterable objects are strings, arrays, array-like objects, maps and sets.

JavaScript Objects are not iterable objects. Due to that you can’t use for...of loop on JavaScript objects. If you try it, you will get a type error saying that object is not iterable. So, remember, when it comes to JavaScript objects use for...in loop. In case of strings, arrays, array-like objects, maps and sets use for...of loop.

// This will not work: for...of loop with objects
// Create simple object
const exampleObj = {
  firstName: 'Jack',
  lastName: 'Ryan'
}

// Try to use for...of loop to loop through exampleObj
for (let objKey of exampleObj) {
  // Log current key, temporarily stored in objKey variable
  console.log(`Current key is: ${objKey}.`)
}
// TypeError: exampleObj is not iterable

// This will work: for...of loop with iterable object (array)
const exampleArray = ['string', 'number', 'boolean', 56, true]

// Use for...of loop to loop through exampleArray
for (let curItem of exampleArray) {
  // Log current item
  console.log(curItem)
}
// 'string'
// 'number'
// 'boolean'
// 56
// true

// This will work: for...of loop with iterable object (string)
const word = 'Doom'

// Use for...of loop to loop through word
for (let curChar of word) {
  // Log current item
  console.log(curChar)
}
// 'D'
// 'o'
// 'o'
// 'm'

#javascript #design development

What is GEEK

Buddha Community

JavaScript Objects – A Friendly Introduction Pt.2
Arvel  Parker

Arvel Parker

1591611780

How to Find Ulimit For user on Linux

How can I find the correct ulimit values for a user account or process on Linux systems?

For proper operation, we must ensure that the correct ulimit values set after installing various software. The Linux system provides means of restricting the number of resources that can be used. Limits set for each Linux user account. However, system limits are applied separately to each process that is running for that user too. For example, if certain thresholds are too low, the system might not be able to server web pages using Nginx/Apache or PHP/Python app. System resource limits viewed or set with the NA command. Let us see how to use the ulimit that provides control over the resources available to the shell and processes.

#[object object] #[object object] #[object object] #[object object] #[object object] #[object object] #[object object] #[object object] #[object object] #[object object]

MEAN Stack Tutorial MongoDB ExpressJS AngularJS NodeJS

We are going to build a full stack Todo App using the MEAN (MongoDB, ExpressJS, AngularJS and NodeJS). This is the last part of three-post series tutorial.

MEAN Stack tutorial series:

AngularJS tutorial for beginners (Part I)
Creating RESTful APIs with NodeJS and MongoDB Tutorial (Part II)
MEAN Stack Tutorial: MongoDB, ExpressJS, AngularJS and NodeJS (Part III) 👈 you are here
Before completing the app, let’s cover some background about the this stack. If you rather jump to the hands-on part click here to get started.

#[object object] #[object object] #[object object] #[object object] #[object object] #[object object] #[object object] #[object object]

CentOS Linux 8.2 Released and Here is How to Upgrade it

CentOS Linux 8.2 (2004) released. It is a Linux distribution derived from RHEL (Red Hat Enterprise Linux) 8.2 source code. CentOS was created when Red Hat stopped providing RHEL free. CentOS 8.2 gives complete control of its open-source software packages and is fully customized for research needs or for running a high-performance website without the need for license fees. Let us see what’s new in CentOS 8.2 (2004) and how to upgrade existing CentOS 8.1.1199 server to 8.2.2004 using the command line.

#[object object] #[object object] #[object object] #[object object] #[object object] #[object object] #[object object]

Tyrique  Littel

Tyrique Littel

1597723200

FreeBSD s3cmd failed [SSL CERTIFICATE_VERIFY_FAILED]

When I install s3cmd package on my FreeBSD system and try to use the s3cmd command I get the following error:

_ERROR: Test failed: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (ssl.c:1091)

How do I fix this problem on FreeBSD Unix system?

Amazon Simple Storage Service (s3 ) is object storage through a web service interface or API. You can store all sorts of files. FreeBSD is free and open-source operating systems. s3cmd is a command-line utility for the Unix-like system to upload, download files to AWS S3 service from the command line.

ERROR: Test failed: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed error and solution

This error indicates that you don’t have packages correctly installed, especially SSL certificates. Let us see how to fix this problem and install s3cmd correctly on FreeBSD to get rid of the problem.

How to install s3cmd on FreeBSD

Search for s3cmd package:

$ pkg search s3cmd

Execute the following command and make sure you install Python 3.x package as Python 2 will be removed after 2020:

$ sudo pkg install py37-s3cmd-2.1.0

Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking integrity... done (0 conflicting)
The following 8 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	libffi: 3.2.1_3
	py37-dateutil: 2.8.1
	py37-magic: 5.38
	py37-s3cmd: 2.1.0
	py37-setuptools: 44.0.0
	py37-six: 1.14.0
	python37: 3.7.8
	readline: 8.0.4

Number of packages to be installed: 8

The process will require 118 MiB more space.

Proceed with this action? [y/N]: y
[rsnapshot] [1/8] Installing readline-8.0.4...
[rsnapshot] [1/8] Extracting readline-8.0.4: 100%
[rsnapshot] [2/8] Installing libffi-3.2.1_3...
....
..
[rsnapshot] [8/8] Extracting py37-s3cmd-2.1.0: 100%
=====
Message from python37-3.7.8:

--
Note that some standard Python modules are provided as separate ports
as they require additional dependencies. They are available as:

py37-gdbm       databases/py-gdbm@py37
py37-sqlite3    databases/py-sqlite3@py37
py37-tkinter    x11-toolkits/py-tkinter@py37

#[object object] #[object object] #[object object] #[object object] #[object object] #[object object] #[object object]

Brain  Crist

Brain Crist

1595434320

Docker Applikationen mit Visual Studio Code debuggen

Mit dem integrierten Debugger von Visual Studio Code lassen sich ASP.NET Core bzw. .NET Core Applikationen einfach und problemlos debuggen. Der Debugger unterstützt auch Remote Debugging, somit lassen sich zum Beispiel .NET Core Programme, die in einem Docker-Container laufen, debuggen.

Als Beispiel Applikation reicht das Default-Template für MVC Applikationen dotnet new mvc

$ md docker-core-debugger
$ cd docker-core-debugger
$ dotnet new mvc

Mit dotnet run prüfen wir kurz, ob die Applikation läuft und unter der Adresse http://localhost:5000 erreichbar ist.

$ dotnet run
$ Hosting environment: Production
$ Content root path: D:\Temp\docker-aspnetcore
$ Now listening on: http://localhost:5000

Die .NET Core Applikation builden wir mit dotnet build und publishen alles mit Hilfe von dotnet publish

$ dotnet build
$ dotnet publish -c Debug -o out --runtime linux-x64

Dabei gilt es zu beachten, dass die Build Configuration mit -c Debug gesetzt ist und das Output Directory auf -o out. Sonst findet Docker die nötigen Binaries nicht. Für den Docker Container brauchen wir nun ein Dockerfile, dass beim Start vorgängig den .NET Core command line debugger (VSDBG) installiert. Das Installations-Script für VSDBG ist unter https://aka.ms/getvsdbgsh abfrufbar.

FROM microsoft/aspnetcore:latest
WORKDIR /app

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
       unzip procps \
    && rm -rf /var/lib/apt/lists/* \
    && curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l /vsdbg

COPY ./out .
ENTRYPOINT ["dotnet", "docker-core-debugger.dll"]

Den Docker Container erstellen wir mit dem docker build Kommando

$ docker build -t coreapp .

und starten die Applikation mit docker run.

$ docker run -d -p 8080:80 --name coreapp coreapp

Jetzt muss Visual Studio Code nur noch wissen, wo unsere Applikation läuft. Dazu definieren wir eine launch.json vom Typ attach und konfigurieren die nötigen Parameter für den Debugger.

{
    "version": "0.2.0",
    "configurations": [
         {
            "name": ".NET Core Remote Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickRemoteProcess}",
            "pipeTransport": {
                "pipeProgram": "docker",
                "pipeArgs": ["exec", "-i coreapp ${debuggerCommand}"],
                "quoteArgs": false,
                "debuggerPath": "/vsdbg/vsdbg",
                "pipeCwd": "${workspaceRoot}"
            },

            "logging": {
                "engineLogging": true,
                "exceptions": true,
                "moduleLoad": true,
                "programOutput": true
            },
        }
    ]
}

Mit F5 starten wir den Debugger. Wenn alles klappt, sollte eine Auswahl der Prozesse des Docker-Containers sichtbar sein.

vscode

Nun muss der dotnet Prozess ausgewählt werden. Der Visual Studio Code Debugger verbindet sich darauf mit VSDBG und wir können wie gewohnt unseren Code debuggen. Dazu setzen wir einen Breakpoint in der Index-Action des HomeControllers und rufen mit dem Browser die URL http://localhost:8080/ auf.

vscode

#[object object] #[object object] #[object object] #[object object] #[object object] #[object object] #[object object]