Nov 19, 2020
Build Your Own Google Home-Enabled Smart Mirror in About Two HoursBuild Your Own Google Home-Enabled Smart Mirror in About Two Hours Build Your Own Google Home-Enabled Smart Mirror in About Two HoursMagic mirror, on the wall, turn off the lights.
h/pi • 253 guides
h/woodworking • 18 guides
h/magicmirror • 4 guides

Watch the video:

Watch the video:

Watch the video:

Apr 5, 2021
55 minutes
Zach's profile pictureZach's profile pictureZach
Joined in 2015 248 guides
Software engineer, designer, tinkerer, and beer enthusiast living in Tampa, Florida.
Jasper is an open-source voice-control platform that runs on a variety of systems, including the Raspberry Pi.
In these interests: pimagicmirrorjasper
Magic mirror, on the wall, turn off the lights.
In these interests: pimagicmirrorgoogle
This guide will show you how to use an Amazon Dash Button to restart or shut down your Raspberry Pi.
In these interests: piamazonnode
Access OctoPrint from anywhere with this OctoPrint Anywhere replacement.
Automate the task that you probably do 10 times per day!
Now you can monitor your prints from the coffee shop!
Get great stuff. Make something great.
Improve voice recording quality on your iPhone in about 30 seconds.
Explore
h/pi • 253 guides
The Raspberry Pi is a small, inexpensive computer developed by the Raspberry Pi Foundation in the United Kingdom.
Explore
h/woodworking • 18 guides
“He who works with his hands is a laborer. He who works with his hands and his head is a craftsman. He who works with his hands and his head and his heart is an artist.” – Francis of Assisi
Explore
h/magicmirror • 4 guides
Mirror, mirror on the wall: who’s the nerdiest of them all?
Nov 19, 2020
h/python • 67 guides
h/code • 69 guides
h/python • 67 guides
h/code • 69 guides
Jun 10, 2021
5 minutes
John's profile pictureJohn's profile pictureJohn
Joined in 2015 304 guides
Software Engineer and creator of howchoo.
This guide will cover the basics of how to use three common regex functions in Python – findall, search, and match. These three are similar, but they each have different a different purpose.
In these interests: pythonregex
In Python, regular expression matches can be returned in the form of a match object. In this guide, I’ll cover the basics of how to make use of a match object.
In these interests: pythonregex
Everything you need to start your smart alarm clock project!
In these interests: pi
A comprehensive guide on Python “for” loops
Specify a parallel filesystem cache for compiled bytecode
Explore
h/python • 67 guides
Python is howchoo’s favorite programming language. We believe python promotes the most organized and performant codebase possible. We also love Django so, naturally, we love Python.
Explore
h/code • 69 guides
Code is poetry — one line at a time.

Learn Multiple Ways to Iterate Over JavaScript Object Properties and Values

JohnJohn John (304)
Nov 19, 2020
5 minutes

This guide demonstrates multiple ways to iterate over a JavaScript object’s properties and values. There are many ways to do this, and each method is slightly nuanced, so for each method we’ll provide a detailed explanation, examples, and a description of when it should be used.

Posted in these interests:
h/javascript27 guides
h/code69 guides

The first method we’ll cover is Object.entries. This method returns an array of an object’s string key-value pairs. There are a few interesting ways to use Object.entries.

Iterating with forEach

Using the forEach method, we can access each entry individually. Notice that we are destructuring entry, and entry[0] is the key while entry[1] is the corresponding value.

const obj = { 'key1': 'value1', 'key2': 'value2' } Object.entries(obj).forEach(entry => { let [key, value] = entry; console.log(key, value); }) // output key1 value1 key2 value2

Iterating with for...of

We can use a slightly nicer syntax to achieve a similar outcome. Using for…of we can destructure each entry in the loop definition.

const obj = { 'key1': 'value1', 'key2': 'value2' } for (let [key, value] of Object.entries(obj)) { console.log(key, value); } // output key1 value1 key2 value2

When should I use Object.entries?

As you can see from the examples above, the most valuable feature of Object.entries is that you have access to both the key and the value. So this is a desirable method to use when you know you’re going to operate on the object’s properties (keys) and the corresponding values.

Limitations of Object.entries

The main thing to consider when using Object.entries is that it will not return properties in the prototype chain. See the following example:

const someObj = { someProp: 123 }; let newObj = Object.create(someObj); newObj.newProp = 456; console.log(newObj.someProp); // => 123 console.log(newObj.newProp); // => 456 // Notice that `someProp` is missing here console.log(Object.entries(newObj)); // => [ [ 'newProp', 456 ] ]

Now, this is probably what we want in most cases, but it’s something to be aware of.

Object.keys returns an array of an object’s enumerable property names.

Enumerable properties are properties set “via simple assignment or via a property initializer”. Since JavaScript objects have a lot of additional properties (e.g. constructor, __proto__), we don’t want to include these types of properties when operating on our object. They can be accessed directly, of course, but won’t be included when iterating over properties.

The usage is simple, see the following example:

const obj = { name: 'Levi Coffin', birthdate: '10/28/1798', city: 'Newport', state: 'Indiana' }; Object.keys(obj) // => [ 'name', 'birthdate', 'city', 'state' ]

To iterate through the object’s properties, we can use forEach:

Object.keys(obj).forEach(key => { console.log(key); });

Or for...of:

for (let key of Object.keys(obj)) { console.log(key); }

And to get the corresponding value, we can use the key for reference. Although, at this point, you ought to use Object.entries from the previous step:

for (let key of Object.keys(obj)) { let value = obj[key]; console.log(key, value); }

When should I use Object.keys?

As the method name implies, you should use Object.keys when you’re only interested in the keys (property names) of an object. If you’re also interested in the values, Object.entries is probably the right tool.

Object.keys is especially useful when we’re using an object to map data. Consider the following object:

const nameAgeMap = { 'Tom': 30, 'Susan': 28, 'Rob': 35, 'Claire': 22 };

Object.keys gives us access to an array of names.

Object.keys(nameAgeMap) // => [ 'Tom', 'Susan', 'Rob', 'Claire' ]

Object.values is the counterpart to Object.keys, and returns an array of the object’s enumerable property values. We covered enumerable properties in the previous step, and this method simply returns the corresponding value for each enumerable property.

Similarly, we can iterate using forEach:

Object.values(obj).forEach(value => { console.log(value); });

Or for...of:

for (let value of Object.values(obj)) { console.log(value); }

When should I use Object.values?

Again, like its counterpart, you should use Object.values when you’re only interested in the object’s values.

Using the same map from the previous step:

const nameAgeMap = { 'Tom': 30, 'Susan': 28, 'Rob': 35, 'Claire': 22 };

We can get the corresponding list of values easily:

Object.values(nameAgeMap) // => [ 30, 28, 35, 22 ]

for…in is similar to Object.keys except it iterates over all of an object’s enumerable properties (excluding Symbols).

In the following example, we’ll create an object newObj from an existing object obj.

let obj = { inheritedProp: 'hello' }; let newObj = Object.create(obj); newObj.ownProp = 'world';

In this example, newObj has its own property called ownProp, and an inherited property called inheritedProp. See how Object.keys only iterates through the object’s own enumerable properties:

Object.keys(newObj).forEach(key => { console.log(key); }); // output ownProp

and for...in iterates over all enumerable properties, including those found in the prototype chain:

for (let key in newObj) { console.log(key); } // output ownProp inheritedProp

When should I use for...in?

Because for...in iterates over all enumerable properties, it is distinguished from the previous three methods. Therefore, you should use this method when you’re interested in iterating over all enumerable properties (and corresponding values) of an object (not just the object’s own properties).

Finally, you can use Object.getOwnPropertyNames to get an array of all of an object’s own property names, including those of non-enumerable properties. So this is similar to Object.keys, except it includes non-enumerable properties as well.

Let’s use an example of an object with inheritance, and we’ll explicitly define properties that are not enumerable:

let obj = { inheritedProp: 'hello' }; let newObj = Object.create(obj, { 'ownProp': { value: 'own property', enumerable: true }, 'nonEnumerableProp': { value: 'not enumerable', enumerable: false } });

Notice we have an inherited property, and two own properties—one enumerable, and one non-enumerable. If we inspect the object we see this:

{ ownProp: 'own property' }

Now, when we use Object.getOwnPropertyNames we’ll get all of the object’s own properties, excluding any inherited properties:

Object.getOwnPropertyNames(newObj) // => [ 'ownProp', 'nonEnumerableProp' ]

And to iterate, just like any Array, we can use forEach:

Object.getOwnPropertyNames(newObj).forEach(name => { console.log(name); });

or for...of:

for (let name of Object.getOwnPropertyNames(newObj)) { console.log(name); }

When should I use Object.getOwnPropertyNames?

This method is distinguished by the fact that it includes non-enumerable properties, so it should be used when this feature is desired.

AshAsh Ash (362)
Apr 13, 2021
2 minutes

In past versions of Windows, uninstalling programs was a little bit tricky. Fortunately once you’ve upgraded to Windows 10, most applications can be uninstalled easily with a few clicks.

Learn Multiple Ways to Iterate Over JavaScript Object Properties and Values

JohnJohn John (304)
Nov 19, 2020
5 minutes

This guide demonstrates multiple ways to iterate over a JavaScript object’s properties and values. There are many ways to do this, and each method is slightly nuanced, so for each method we’ll provide a detailed explanation, examples, and a description of when it should be used.

Posted in these interests:
h/javascript27 guides
h/code69 guides

The first method we’ll cover is Object.entries. This method returns an array of an object’s string key-value pairs. There are a few interesting ways to use Object.entries.

Iterating with forEach

Using the forEach method, we can access each entry individually. Notice that we are destructuring entry, and entry[0] is the key while entry[1] is the corresponding value.

const obj = { 'key1': 'value1', 'key2': 'value2' } Object.entries(obj).forEach(entry => { let [key, value] = entry; console.log(key, value); }) // output key1 value1 key2 value2

Iterating with for...of

We can use a slightly nicer syntax to achieve a similar outcome. Using for…of we can destructure each entry in the loop definition.

const obj = { 'key1': 'value1', 'key2': 'value2' } for (let [key, value] of Object.entries(obj)) { console.log(key, value); } // output key1 value1 key2 value2

When should I use Object.entries?

As you can see from the examples above, the most valuable feature of Object.entries is that you have access to both the key and the value. So this is a desirable method to use when you know you’re going to operate on the object’s properties (keys) and the corresponding values.

Limitations of Object.entries

The main thing to consider when using Object.entries is that it will not return properties in the prototype chain. See the following example:

const someObj = { someProp: 123 }; let newObj = Object.create(someObj); newObj.newProp = 456; console.log(newObj.someProp); // => 123 console.log(newObj.newProp); // => 456 // Notice that `someProp` is missing here console.log(Object.entries(newObj)); // => [ [ 'newProp', 456 ] ]

Now, this is probably what we want in most cases, but it’s something to be aware of.

Object.keys returns an array of an object’s enumerable property names.

Enumerable properties are properties set “via simple assignment or via a property initializer”. Since JavaScript objects have a lot of additional properties (e.g. constructor, __proto__), we don’t want to include these types of properties when operating on our object. They can be accessed directly, of course, but won’t be included when iterating over properties.

The usage is simple, see the following example:

const obj = { name: 'Levi Coffin', birthdate: '10/28/1798', city: 'Newport', state: 'Indiana' }; Object.keys(obj) // => [ 'name', 'birthdate', 'city', 'state' ]

To iterate through the object’s properties, we can use forEach:

Object.keys(obj).forEach(key => { console.log(key); });

Or for...of:

for (let key of Object.keys(obj)) { console.log(key); }

And to get the corresponding value, we can use the key for reference. Although, at this point, you ought to use Object.entries from the previous step:

for (let key of Object.keys(obj)) { let value = obj[key]; console.log(key, value); }

When should I use Object.keys?

As the method name implies, you should use Object.keys when you’re only interested in the keys (property names) of an object. If you’re also interested in the values, Object.entries is probably the right tool.

Object.keys is especially useful when we’re using an object to map data. Consider the following object:

const nameAgeMap = { 'Tom': 30, 'Susan': 28, 'Rob': 35, 'Claire': 22 };

Object.keys gives us access to an array of names.

Object.keys(nameAgeMap) // => [ 'Tom', 'Susan', 'Rob', 'Claire' ]

Object.values is the counterpart to Object.keys, and returns an array of the object’s enumerable property values. We covered enumerable properties in the previous step, and this method simply returns the corresponding value for each enumerable property.

Similarly, we can iterate using forEach:

Object.values(obj).forEach(value => { console.log(value); });

Or for...of:

for (let value of Object.values(obj)) { console.log(value); }

When should I use Object.values?

Again, like its counterpart, you should use Object.values when you’re only interested in the object’s values.

Using the same map from the previous step:

const nameAgeMap = { 'Tom': 30, 'Susan': 28, 'Rob': 35, 'Claire': 22 };

We can get the corresponding list of values easily:

Object.values(nameAgeMap) // => [ 30, 28, 35, 22 ]

for…in is similar to Object.keys except it iterates over all of an object’s enumerable properties (excluding Symbols).

In the following example, we’ll create an object newObj from an existing object obj.

let obj = { inheritedProp: 'hello' }; let newObj = Object.create(obj); newObj.ownProp = 'world';

In this example, newObj has its own property called ownProp, and an inherited property called inheritedProp. See how Object.keys only iterates through the object’s own enumerable properties:

Object.keys(newObj).forEach(key => { console.log(key); }); // output ownProp

and for...in iterates over all enumerable properties, including those found in the prototype chain:

for (let key in newObj) { console.log(key); } // output ownProp inheritedProp

When should I use for...in?

Because for...in iterates over all enumerable properties, it is distinguished from the previous three methods. Therefore, you should use this method when you’re interested in iterating over all enumerable properties (and corresponding values) of an object (not just the object’s own properties).

Finally, you can use Object.getOwnPropertyNames to get an array of all of an object’s own property names, including those of non-enumerable properties. So this is similar to Object.keys, except it includes non-enumerable properties as well.

Let’s use an example of an object with inheritance, and we’ll explicitly define properties that are not enumerable:

let obj = { inheritedProp: 'hello' }; let newObj = Object.create(obj, { 'ownProp': { value: 'own property', enumerable: true }, 'nonEnumerableProp': { value: 'not enumerable', enumerable: false } });

Notice we have an inherited property, and two own properties—one enumerable, and one non-enumerable. If we inspect the object we see this:

{ ownProp: 'own property' }

Now, when we use Object.getOwnPropertyNames we’ll get all of the object’s own properties, excluding any inherited properties:

Object.getOwnPropertyNames(newObj) // => [ 'ownProp', 'nonEnumerableProp' ]

And to iterate, just like any Array, we can use forEach:

Object.getOwnPropertyNames(newObj).forEach(name => { console.log(name); });

or for...of:

for (let name of Object.getOwnPropertyNames(newObj)) { console.log(name); }

When should I use Object.getOwnPropertyNames?

This method is distinguished by the fact that it includes non-enumerable properties, so it should be used when this feature is desired.

AshAsh Ash (362)
Apr 13, 2021
2 minutes

In past versions of Windows, uninstalling programs was a little bit tricky. Fortunately once you’ve upgraded to Windows 10, most applications can be uninstalled easily with a few clicks.

 
2

Learn Multiple Ways to Iterate Over JavaScript Object Properties and Values

JohnJohn John (304)
Nov 19, 2020
5 minutes

This guide demonstrates multiple ways to iterate over a JavaScript object’s properties and values. There are many ways to do this, and each method is slightly nuanced, so for each method we’ll provide a detailed explanation, examples, and a description of when it should be used.

Posted in these interests:
h/javascript27 guides
h/code69 guides

The first method we’ll cover is Object.entries. This method returns an array of an object’s string key-value pairs. There are a few interesting ways to use Object.entries.

Iterating with forEach

Using the forEach method, we can access each entry individually. Notice that we are destructuring entry, and entry[0] is the key while entry[1] is the corresponding value.

const obj = { 'key1': 'value1', 'key2': 'value2' } Object.entries(obj).forEach(entry => { let [key, value] = entry; console.log(key, value); }) // output key1 value1 key2 value2

Iterating with for...of

We can use a slightly nicer syntax to achieve a similar outcome. Using for…of we can destructure each entry in the loop definition.

const obj = { 'key1': 'value1', 'key2': 'value2' } for (let [key, value] of Object.entries(obj)) { console.log(key, value); } // output key1 value1 key2 value2

When should I use Object.entries?

As you can see from the examples above, the most valuable feature of Object.entries is that you have access to both the key and the value. So this is a desirable method to use when you know you’re going to operate on the object’s properties (keys) and the corresponding values.

Limitations of Object.entries

The main thing to consider when using Object.entries is that it will not return properties in the prototype chain. See the following example:

const someObj = { someProp: 123 }; let newObj = Object.create(someObj); newObj.newProp = 456; console.log(newObj.someProp); // => 123 console.log(newObj.newProp); // => 456 // Notice that `someProp` is missing here console.log(Object.entries(newObj)); // => [ [ 'newProp', 456 ] ]

Now, this is probably what we want in most cases, but it’s something to be aware of.

Object.keys returns an array of an object’s enumerable property names.

Enumerable properties are properties set “via simple assignment or via a property initializer”. Since JavaScript objects have a lot of additional properties (e.g. constructor, __proto__), we don’t want to include these types of properties when operating on our object. They can be accessed directly, of course, but won’t be included when iterating over properties.

The usage is simple, see the following example:

const obj = { name: 'Levi Coffin', birthdate: '10/28/1798', city: 'Newport', state: 'Indiana' }; Object.keys(obj) // => [ 'name', 'birthdate', 'city', 'state' ]

To iterate through the object’s properties, we can use forEach:

Object.keys(obj).forEach(key => { console.log(key); });

Or for...of:

for (let key of Object.keys(obj)) { console.log(key); }

And to get the corresponding value, we can use the key for reference. Although, at this point, you ought to use Object.entries from the previous step:

for (let key of Object.keys(obj)) { let value = obj[key]; console.log(key, value); }

When should I use Object.keys?

As the method name implies, you should use Object.keys when you’re only interested in the keys (property names) of an object. If you’re also interested in the values, Object.entries is probably the right tool.

Object.keys is especially useful when we’re using an object to map data. Consider the following object:

const nameAgeMap = { 'Tom': 30, 'Susan': 28, 'Rob': 35, 'Claire': 22 };

Object.keys gives us access to an array of names.

Object.keys(nameAgeMap) // => [ 'Tom', 'Susan', 'Rob', 'Claire' ]

Object.values is the counterpart to Object.keys, and returns an array of the object’s enumerable property values. We covered enumerable properties in the previous step, and this method simply returns the corresponding value for each enumerable property.

Similarly, we can iterate using forEach:

Object.values(obj).forEach(value => { console.log(value); });

Or for...of:

for (let value of Object.values(obj)) { console.log(value); }

When should I use Object.values?

Again, like its counterpart, you should use Object.values when you’re only interested in the object’s values.

Using the same map from the previous step:

const nameAgeMap = { 'Tom': 30, 'Susan': 28, 'Rob': 35, 'Claire': 22 };

We can get the corresponding list of values easily:

Object.values(nameAgeMap) // => [ 30, 28, 35, 22 ]

for…in is similar to Object.keys except it iterates over all of an object’s enumerable properties (excluding Symbols).

In the following example, we’ll create an object newObj from an existing object obj.

let obj = { inheritedProp: 'hello' }; let newObj = Object.create(obj); newObj.ownProp = 'world';

In this example, newObj has its own property called ownProp, and an inherited property called inheritedProp. See how Object.keys only iterates through the object’s own enumerable properties:

Object.keys(newObj).forEach(key => { console.log(key); }); // output ownProp

and for...in iterates over all enumerable properties, including those found in the prototype chain:

for (let key in newObj) { console.log(key); } // output ownProp inheritedProp

When should I use for...in?

Because for...in iterates over all enumerable properties, it is distinguished from the previous three methods. Therefore, you should use this method when you’re interested in iterating over all enumerable properties (and corresponding values) of an object (not just the object’s own properties).

Finally, you can use Object.getOwnPropertyNames to get an array of all of an object’s own property names, including those of non-enumerable properties. So this is similar to Object.keys, except it includes non-enumerable properties as well.

Let’s use an example of an object with inheritance, and we’ll explicitly define properties that are not enumerable:

let obj = { inheritedProp: 'hello' }; let newObj = Object.create(obj, { 'ownProp': { value: 'own property', enumerable: true }, 'nonEnumerableProp': { value: 'not enumerable', enumerable: false } });

Notice we have an inherited property, and two own properties—one enumerable, and one non-enumerable. If we inspect the object we see this:

{ ownProp: 'own property' }

Now, when we use Object.getOwnPropertyNames we’ll get all of the object’s own properties, excluding any inherited properties:

Object.getOwnPropertyNames(newObj) // => [ 'ownProp', 'nonEnumerableProp' ]

And to iterate, just like any Array, we can use forEach:

Object.getOwnPropertyNames(newObj).forEach(name => { console.log(name); });

or for...of:

for (let name of Object.getOwnPropertyNames(newObj)) { console.log(name); }

When should I use Object.getOwnPropertyNames?

This method is distinguished by the fact that it includes non-enumerable properties, so it should be used when this feature is desired.

AshAsh Ash (362)
Apr 13, 2021
2 minutes

In past versions of Windows, uninstalling programs was a little bit tricky. Fortunately once you’ve upgraded to Windows 10, most applications can be uninstalled easily with a few clicks.

Learn Multiple Ways to Iterate Over JavaScript Object Properties and Values

JohnJohn John (304)
Nov 19, 2020
5 minutes

This guide demonstrates multiple ways to iterate over a JavaScript object’s properties and values. There are many ways to do this, and each method is slightly nuanced, so for each method we’ll provide a detailed explanation, examples, and a description of when it should be used.

Posted in these interests:
h/javascript27 guides
h/code69 guides

Learn Multiple Ways to Iterate Over JavaScript Object Properties and Values

JohnJohn John (304)
Nov 19, 2020
5 minutes
John
 
2
Posted in these interests:
h/javascript27 guides
h/code69 guides
Posted in these interests:
h/javascript27 guides
h/code69 guides
Table of Contents

Object Iteration Methods:

  1. Object.entries
  2. Object.keys
  3. Object.values
  4. for…in
  5. Object.getOwnPropertyNames
 
2
In these interests
h/javascript27 guides
h/code69 guides
h/javascript27 guides
h/code69 guides

The first method we’ll cover is Object.entries. This method returns an array of an object’s string key-value pairs. There are a few interesting ways to use Object.entries.

Iterating with forEach

Using the forEach method, we can access each entry individually. Notice that we are destructuring entry, and entry[0] is the key while entry[1] is the corresponding value.

const obj = { 'key1': 'value1', 'key2': 'value2' } Object.entries(obj).forEach(entry => { let [key, value] = entry; console.log(key, value); }) // output key1 value1 key2 value2

Iterating with for...of

We can use a slightly nicer syntax to achieve a similar outcome. Using for…of we can destructure each entry in the loop definition.

const obj = { 'key1': 'value1', 'key2': 'value2' } for (let [key, value] of Object.entries(obj)) { console.log(key, value); } // output key1 value1 key2 value2

When should I use Object.entries?

As you can see from the examples above, the most valuable feature of Object.entries is that you have access to both the key and the value. So this is a desirable method to use when you know you’re going to operate on the object’s properties (keys) and the corresponding values.

Limitations of Object.entries

The main thing to consider when using Object.entries is that it will not return properties in the prototype chain. See the following example:

const someObj = { someProp: 123 }; let newObj = Object.create(someObj); newObj.newProp = 456; console.log(newObj.someProp); // => 123 console.log(newObj.newProp); // => 456 // Notice that `someProp` is missing here console.log(Object.entries(newObj)); // => [ [ 'newProp', 456 ] ]

Now, this is probably what we want in most cases, but it’s something to be aware of.

The first method we’ll cover is Object.entries. This method returns an array of an object’s string key-value pairs. There are a few interesting ways to use Object.entries.

Iterating with forEach

Using the forEach method, we can access each entry individually. Notice that we are destructuring entry, and entry[0] is the key while entry[1] is the corresponding value.

const obj = { 'key1': 'value1', 'key2': 'value2' } Object.entries(obj).forEach(entry => { let [key, value] = entry; console.log(key, value); }) // output key1 value1 key2 value2

Iterating with for...of

We can use a slightly nicer syntax to achieve a similar outcome. Using for…of we can destructure each entry in the loop definition.

const obj = { 'key1': 'value1', 'key2': 'value2' } for (let [key, value] of Object.entries(obj)) { console.log(key, value); } // output key1 value1 key2 value2

When should I use Object.entries?

As you can see from the examples above, the most valuable feature of Object.entries is that you have access to both the key and the value. So this is a desirable method to use when you know you’re going to operate on the object’s properties (keys) and the corresponding values.

Limitations of Object.entries

The main thing to consider when using Object.entries is that it will not return properties in the prototype chain. See the following example:

const someObj = { someProp: 123 }; let newObj = Object.create(someObj); newObj.newProp = 456; console.log(newObj.someProp); // => 123 console.log(newObj.newProp); // => 456 // Notice that `someProp` is missing here console.log(Object.entries(newObj)); // => [ [ 'newProp', 456 ] ]

Now, this is probably what we want in most cases, but it’s something to be aware of.

Object.entries

The Difference Between "for...in" and "for...of" in JavaScript

Object.keys returns an array of an object’s enumerable property names.

Enumerable properties are properties set “via simple assignment or via a property initializer”. Since JavaScript objects have a lot of additional properties (e.g. constructor, __proto__), we don’t want to include these types of properties when operating on our object. They can be accessed directly, of course, but won’t be included when iterating over properties.

The usage is simple, see the following example:

const obj = { name: 'Levi Coffin', birthdate: '10/28/1798', city: 'Newport', state: 'Indiana' }; Object.keys(obj) // => [ 'name', 'birthdate', 'city', 'state' ]

To iterate through the object’s properties, we can use forEach:

Object.keys(obj).forEach(key => { console.log(key); });

Or for...of:

for (let key of Object.keys(obj)) { console.log(key); }

And to get the corresponding value, we can use the key for reference. Although, at this point, you ought to use Object.entries from the previous step:

for (let key of Object.keys(obj)) { let value = obj[key]; console.log(key, value); }

When should I use Object.keys?

As the method name implies, you should use Object.keys when you’re only interested in the keys (property names) of an object. If you’re also interested in the values, Object.entries is probably the right tool.

Object.keys is especially useful when we’re using an object to map data. Consider the following object:

const nameAgeMap = { 'Tom': 30, 'Susan': 28, 'Rob': 35, 'Claire': 22 };

Object.keys gives us access to an array of names.

Object.keys(nameAgeMap) // => [ 'Tom', 'Susan', 'Rob', 'Claire' ]

Object.keys returns an array of an object’s enumerable property names.

Enumerable properties are properties set “via simple assignment or via a property initializer”. Since JavaScript objects have a lot of additional properties (e.g. constructor, __proto__), we don’t want to include these types of properties when operating on our object. They can be accessed directly, of course, but won’t be included when iterating over properties.

The usage is simple, see the following example:

const obj = { name: 'Levi Coffin', birthdate: '10/28/1798', city: 'Newport', state: 'Indiana' }; Object.keys(obj) // => [ 'name', 'birthdate', 'city', 'state' ]

To iterate through the object’s properties, we can use forEach:

Object.keys(obj).forEach(key => { console.log(key); });

Or for...of:

for (let key of Object.keys(obj)) { console.log(key); }

And to get the corresponding value, we can use the key for reference. Although, at this point, you ought to use Object.entries from the previous step:

for (let key of Object.keys(obj)) { let value = obj[key]; console.log(key, value); }

When should I use Object.keys?

As the method name implies, you should use Object.keys when you’re only interested in the keys (property names) of an object. If you’re also interested in the values, Object.entries is probably the right tool.

Object.keys is especially useful when we’re using an object to map data. Consider the following object:

const nameAgeMap = { 'Tom': 30, 'Susan': 28, 'Rob': 35, 'Claire': 22 };

Object.keys gives us access to an array of names.

Object.keys(nameAgeMap) // => [ 'Tom', 'Susan', 'Rob', 'Claire' ]

Object.keys

Object.values is the counterpart to Object.keys, and returns an array of the object’s enumerable property values. We covered enumerable properties in the previous step, and this method simply returns the corresponding value for each enumerable property.

Similarly, we can iterate using forEach:

Object.values(obj).forEach(value => { console.log(value); });

Or for...of:

for (let value of Object.values(obj)) { console.log(value); }

When should I use Object.values?

Again, like its counterpart, you should use Object.values when you’re only interested in the object’s values.

Using the same map from the previous step:

const nameAgeMap = { 'Tom': 30, 'Susan': 28, 'Rob': 35, 'Claire': 22 };

We can get the corresponding list of values easily:

Object.values(nameAgeMap) // => [ 30, 28, 35, 22 ]

Object.values is the counterpart to Object.keys, and returns an array of the object’s enumerable property values. We covered enumerable properties in the previous step, and this method simply returns the corresponding value for each enumerable property.

Similarly, we can iterate using forEach:

Object.values(obj).forEach(value => { console.log(value); });

Or for...of:

for (let value of Object.values(obj)) { console.log(value); }

When should I use Object.values?

Again, like its counterpart, you should use Object.values when you’re only interested in the object’s values.

Using the same map from the previous step:

const nameAgeMap = { 'Tom': 30, 'Susan': 28, 'Rob': 35, 'Claire': 22 };

We can get the corresponding list of values easily:

Object.values(nameAgeMap) // => [ 30, 28, 35, 22 ]

Object.values

for…in is similar to Object.keys except it iterates over all of an object’s enumerable properties (excluding Symbols).

In the following example, we’ll create an object newObj from an existing object obj.

let obj = { inheritedProp: 'hello' }; let newObj = Object.create(obj); newObj.ownProp = 'world';

In this example, newObj has its own property called ownProp, and an inherited property called inheritedProp. See how Object.keys only iterates through the object’s own enumerable properties:

Object.keys(newObj).forEach(key => { console.log(key); }); // output ownProp

and for...in iterates over all enumerable properties, including those found in the prototype chain:

for (let key in newObj) { console.log(key); } // output ownProp inheritedProp

When should I use for...in?

Because for...in iterates over all enumerable properties, it is distinguished from the previous three methods. Therefore, you should use this method when you’re interested in iterating over all enumerable properties (and corresponding values) of an object (not just the object’s own properties).

for…in is similar to Object.keys except it iterates over all of an object’s enumerable properties (excluding Symbols).

In the following example, we’ll create an object newObj from an existing object obj.

let obj = { inheritedProp: 'hello' }; let newObj = Object.create(obj); newObj.ownProp = 'world';

In this example, newObj has its own property called ownProp, and an inherited property called inheritedProp. See how Object.keys only iterates through the object’s own enumerable properties:

Object.keys(newObj).forEach(key => { console.log(key); }); // output ownProp

and for...in iterates over all enumerable properties, including those found in the prototype chain:

for (let key in newObj) { console.log(key); } // output ownProp inheritedProp

When should I use for...in?

Because for...in iterates over all enumerable properties, it is distinguished from the previous three methods. Therefore, you should use this method when you’re interested in iterating over all enumerable properties (and corresponding values) of an object (not just the object’s own properties).

for…in

The Difference Between "for...in" and "for...of" in JavaScript

Finally, you can use Object.getOwnPropertyNames to get an array of all of an object’s own property names, including those of non-enumerable properties. So this is similar to Object.keys, except it includes non-enumerable properties as well.

Let’s use an example of an object with inheritance, and we’ll explicitly define properties that are not enumerable:

let obj = { inheritedProp: 'hello' }; let newObj = Object.create(obj, { 'ownProp': { value: 'own property', enumerable: true }, 'nonEnumerableProp': { value: 'not enumerable', enumerable: false } });

Notice we have an inherited property, and two own properties—one enumerable, and one non-enumerable. If we inspect the object we see this:

{ ownProp: 'own property' }

Now, when we use Object.getOwnPropertyNames we’ll get all of the object’s own properties, excluding any inherited properties:

Object.getOwnPropertyNames(newObj) // => [ 'ownProp', 'nonEnumerableProp' ]

And to iterate, just like any Array, we can use forEach:

Object.getOwnPropertyNames(newObj).forEach(name => { console.log(name); });

or for...of:

for (let name of Object.getOwnPropertyNames(newObj)) { console.log(name); }

When should I use Object.getOwnPropertyNames?

This method is distinguished by the fact that it includes non-enumerable properties, so it should be used when this feature is desired.

Finally, you can use Object.getOwnPropertyNames to get an array of all of an object’s own property names, including those of non-enumerable properties. So this is similar to Object.keys, except it includes non-enumerable properties as well.

Let’s use an example of an object with inheritance, and we’ll explicitly define properties that are not enumerable:

let obj = { inheritedProp: 'hello' }; let newObj = Object.create(obj, { 'ownProp': { value: 'own property', enumerable: true }, 'nonEnumerableProp': { value: 'not enumerable', enumerable: false } });

Notice we have an inherited property, and two own properties—one enumerable, and one non-enumerable. If we inspect the object we see this:

{ ownProp: 'own property' }

Now, when we use Object.getOwnPropertyNames we’ll get all of the object’s own properties, excluding any inherited properties:

Object.getOwnPropertyNames(newObj) // => [ 'ownProp', 'nonEnumerableProp' ]

And to iterate, just like any Array, we can use forEach:

Object.getOwnPropertyNames(newObj).forEach(name => { console.log(name); });

or for...of:

for (let name of Object.getOwnPropertyNames(newObj)) { console.log(name); }

When should I use Object.getOwnPropertyNames?

This method is distinguished by the fact that it includes non-enumerable properties, so it should be used when this feature is desired.

Object.getOwnPropertyNames

AshAsh Ash (362)
Apr 13, 2021
2 minutes

In past versions of Windows, uninstalling programs was a little bit tricky. Fortunately once you’ve upgraded to Windows 10, most applications can be uninstalled easily with a few clicks.

AshAsh Ash (362)
Apr 13, 2021
2 minutes

In past versions of Windows, uninstalling programs was a little bit tricky. Fortunately once you’ve upgraded to Windows 10, most applications can be uninstalled easily with a few clicks.

NEXT UP
How to Uninstall Programs on Windows 10
Uninstall programs on Windows 10
AshAsh Ash (362)
Apr 13, 2021
2 minutes
Ash Continue reading
Share this guide!
RedditEmailText
John's profile pictureJohn's profile pictureJohn
Joined in 2015 304 guides
Software Engineer and creator of howchoo.
John's profile picture
Related to this guide:
Uninstall programs on Windows 10Uninstall programs on Windows 10
In past versions of Windows, uninstalling programs was a little bit tricky. Fortunately once you’ve upgraded to Windows 10, most applications can be uninstalled easily with a few clicks.
In these interests: windows
Merge Dictionaries in PythonMerge Dictionaries in Python
In this guide we’ll cover how to merge two (or more) dictionaries in Python. There are a few ways to do it, so we’ll cover multiple methods.
In these interests: python
Coffee cup.Coffee cup.
For the most caffeinated coffee consumers.
In these interests: foodcoffee
Uninstall programs on Windows 10Uninstall programs on Windows 10
In past versions of Windows, uninstalling programs was a little bit tricky. Fortunately once you’ve upgraded to Windows 10, most applications can be uninstalled easily with a few clicks.
In these interests: windows
Ash's profile pictureView guide
In these interests: windows
windows
Merge Dictionaries in PythonMerge Dictionaries in Python
In this guide we’ll cover how to merge two (or more) dictionaries in Python. There are a few ways to do it, so we’ll cover multiple methods.
In these interests: python
John's profile pictureView guide
In these interests: python
python
Coffee cup.Coffee cup.
For the most caffeinated coffee consumers.
In these interests: foodcoffee
Tayler's profile pictureView guide
In these interests: foodcoffee
foodcoffee
People also read:
connect quest 2 to pcconnect quest 2 to pc
The best method to connecting the Quest 2 to PC.
How to Resize an Image in InDesignHow to Resize an Image in InDesign
There are two options for resizing in InDesign: the easy way and the precise way.
connect quest 2 to pcconnect quest 2 to pc
connect quest 2 to pcHow To Connect an Oculus Quest 2 to a PC via USB
Learn the slow (and fast) way to append elements to the DOM
How to Resize an Image in InDesignHow to Resize an Image in InDesign
How to Resize an Image in InDesignHow to Resize an Image in InDesign
How to Reverse a String in Python 3
Default BrowserDefault Browser
Default BrowserHow to Change Your Default Web Browser on Windows, Mac, or Linux
How to Sort Data in Google SheetsHow to Sort Data in Google Sheets
How to Sort Data in Google SheetsHow to Sort Data in Google Sheets
Unit Testing in JavaScript – Mocha, Chai and Sinon – a Beginner’s Guide
Remove Elements From an Array in JavaScript
breed horses in minecraftbreed horses in minecraft
breed horses in minecraftHow To Breed Horses in Minecraft
connect quest 2 to pc airlinkconnect quest 2 to pc airlink
connect quest 2 to pc airlinkHow To Wirelessly Connect the Oculus Quest 2 to a PC With Airlink
Posted in these interests:
javascriptjavascript
Explore
h/javascript 27 guides
Array(16).join(“wat” – 1) + ” Batman!”;
codecode
Explore
h/code 69 guides
Code is poetry — one line at a time.
javascriptjavascript
Explore
h/javascript 27 guides
Array(16).join(“wat” – 1) + ” Batman!”;
Explore
codecode
Explore
h/code 69 guides
Code is poetry — one line at a time.
Explore
Discuss this guide!
Discover interesting things!
Explore Howchoo’s most popular interests.
Explore

Follow @howchoo and learn cool things:

Are you a passionate writer? We’re hiring!

Write for Howchoo

Like what we do?

Donate

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

Write for HowchooDonate

GitHub Pull Requests: How and Why to Use Pull Requests

Become a PR pro in about 5 minutes.
JohnJohn John (304)
Nov 19, 2020
5 minutes

At howchoo, our code is on private Github repos. We’ve recently started using pull requests to submit new changes to the code base. Likewise, we’ve been using Github issues for a while to keep track of bug fixes and small tasks. Our workflow has been improved significantly due to a few hidden gems in Github. In this guide, I’ll show how to make pull requests as well as a few other workflow tips.

Posted in these interests:
h/webdev • 60 guides
h/code • 69 guides
GitHubGitHub
h/github • 8 guides
Finding the pull requestsFinding the pull requests

When viewing a repository in your Github account, you should see an icon with the words “Pull requests”. Fitting, right? Click on that link to go to the pull request page.

Click "New pull request"Click "New pull request"

The pull requests page will show you existing, open pull requests. You’ll find a button at the top that says “New pull request”. Click that one.

Choose your branchesChoose your branches

At this point you’ll choose your branches, on the left the branch you’re merging into and on the right the branch you’re merging from. At this point, it’s assumed that you’ve pushed your branch to origin. The branch you’re merging into is often master or depending on your branching model it could be called develop. When this pull request is closed, the compare branch will be merged into the base branch.

Create the pull requestCreate the pull request

Once you’ve selected your branches, click “Create pull request”. This won’t create it but will give you the chance to leave a comment. It’s a good idea to leave a descriptive comment about what changes will be merged. It is assumed that another developer will be reviewing these changes so comments are helpful. At this point, you can scroll down to see a diff of the files changed. This is a good time to do a final review of your code to make sure it’s ready to be merged. Now click “Create pull request” again to actually create the request.

Pull requests are a great way to review code. Once you’ve created the pull request you can send the url to someone else in the organization. They will be able to see the diff, leave comments, and eventually close and merge the pull request if everything looks good.

Wouldn’t it be cool if Github would automatically close issues with a pull request? Well, they do! Before submitting the pull request, you should use the following language in a commit message:

Fixes #167
where 167 is the issue number this branch should close. By typing this in the commit message, issue number 167 will automatically be closed when the branch is merged into master. There are a number of different phrases you can write in the commit message to force the issue to be closed. A full list can be found here – Closing issues via commit messages.
GitHub Codespaces is officially in beta.
AshAsh Ash (362)
Feb 4, 2021
0

Earlier this week, GitHub announced the launch of a new cloud-hosted IDE known as GitHub Codespaces. This new service is a full development environment based on Microsoft’s Visual Studio Code.

GitHub Pull Requests: How and Why to Use Pull Requests

Become a PR pro in about 5 minutes.
JohnJohn John (304)
Nov 19, 2020
5 minutes

At howchoo, our code is on private Github repos. We’ve recently started using pull requests to submit new changes to the code base. Likewise, we’ve been using Github issues for a while to keep track of bug fixes and small tasks. Our workflow has been improved significantly due to a few hidden gems in Github. In this guide, I’ll show how to make pull requests as well as a few other workflow tips.

Posted in these interests:
h/webdev • 60 guides
h/code • 69 guides
GitHubGitHub
h/github • 8 guides
Finding the pull requestsFinding the pull requests

When viewing a repository in your Github account, you should see an icon with the words “Pull requests”. Fitting, right? Click on that link to go to the pull request page.

Click "New pull request"Click "New pull request"

The pull requests page will show you existing, open pull requests. You’ll find a button at the top that says “New pull request”. Click that one.

Choose your branchesChoose your branches

At this point you’ll choose your branches, on the left the branch you’re merging into and on the right the branch you’re merging from. At this point, it’s assumed that you’ve pushed your branch to origin. The branch you’re merging into is often master or depending on your branching model it could be called develop. When this pull request is closed, the compare branch will be merged into the base branch.

Create the pull requestCreate the pull request

Once you’ve selected your branches, click “Create pull request”. This won’t create it but will give you the chance to leave a comment. It’s a good idea to leave a descriptive comment about what changes will be merged. It is assumed that another developer will be reviewing these changes so comments are helpful. At this point, you can scroll down to see a diff of the files changed. This is a good time to do a final review of your code to make sure it’s ready to be merged. Now click “Create pull request” again to actually create the request.

Pull requests are a great way to review code. Once you’ve created the pull request you can send the url to someone else in the organization. They will be able to see the diff, leave comments, and eventually close and merge the pull request if everything looks good.

Wouldn’t it be cool if Github would automatically close issues with a pull request? Well, they do! Before submitting the pull request, you should use the following language in a commit message:

Fixes #167
where 167 is the issue number this branch should close. By typing this in the commit message, issue number 167 will automatically be closed when the branch is merged into master. There are a number of different phrases you can write in the commit message to force the issue to be closed. A full list can be found here – Closing issues via commit messages.
GitHub Codespaces is officially in beta.
AshAsh Ash (362)
Feb 4, 2021
0

Earlier this week, GitHub announced the launch of a new cloud-hosted IDE known as GitHub Codespaces. This new service is a full development environment based on Microsoft’s Visual Studio Code.

 
1

GitHub Pull Requests: How and Why to Use Pull Requests

Become a PR pro in about 5 minutes.
JohnJohn John (304)
Nov 19, 2020
5 minutes

At howchoo, our code is on private Github repos. We’ve recently started using pull requests to submit new changes to the code base. Likewise, we’ve been using Github issues for a while to keep track of bug fixes and small tasks. Our workflow has been improved significantly due to a few hidden gems in Github. In this guide, I’ll show how to make pull requests as well as a few other workflow tips.

Posted in these interests:
h/webdev • 60 guides
h/code • 69 guides
GitHubGitHub
h/github • 8 guides
Finding the pull requestsFinding the pull requests

When viewing a repository in your Github account, you should see an icon with the words “Pull requests”. Fitting, right? Click on that link to go to the pull request page.

Click "New pull request"Click "New pull request"

The pull requests page will show you existing, open pull requests. You’ll find a button at the top that says “New pull request”. Click that one.

Choose your branchesChoose your branches

At this point you’ll choose your branches, on the left the branch you’re merging into and on the right the branch you’re merging from. At this point, it’s assumed that you’ve pushed your branch to origin. The branch you’re merging into is often master or depending on your branching model it could be called develop. When this pull request is closed, the compare branch will be merged into the base branch.

Create the pull requestCreate the pull request

Once you’ve selected your branches, click “Create pull request”. This won’t create it but will give you the chance to leave a comment. It’s a good idea to leave a descriptive comment about what changes will be merged. It is assumed that another developer will be reviewing these changes so comments are helpful. At this point, you can scroll down to see a diff of the files changed. This is a good time to do a final review of your code to make sure it’s ready to be merged. Now click “Create pull request” again to actually create the request.

Pull requests are a great way to review code. Once you’ve created the pull request you can send the url to someone else in the organization. They will be able to see the diff, leave comments, and eventually close and merge the pull request if everything looks good.

Wouldn’t it be cool if Github would automatically close issues with a pull request? Well, they do! Before submitting the pull request, you should use the following language in a commit message:

Fixes #167
where 167 is the issue number this branch should close. By typing this in the commit message, issue number 167 will automatically be closed when the branch is merged into master. There are a number of different phrases you can write in the commit message to force the issue to be closed. A full list can be found here – Closing issues via commit messages.
GitHub Codespaces is officially in beta.
AshAsh Ash (362)
Feb 4, 2021
0

Earlier this week, GitHub announced the launch of a new cloud-hosted IDE known as GitHub Codespaces. This new service is a full development environment based on Microsoft’s Visual Studio Code.

GitHub Pull Requests: How and Why to Use Pull Requests

Become a PR pro in about 5 minutes.
JohnJohn John (304)
Nov 19, 2020
5 minutes

At howchoo, our code is on private Github repos. We’ve recently started using pull requests to submit new changes to the code base. Likewise, we’ve been using Github issues for a while to keep track of bug fixes and small tasks. Our workflow has been improved significantly due to a few hidden gems in Github. In this guide, I’ll show how to make pull requests as well as a few other workflow tips.

Posted in these interests:
h/webdev • 60 guides
h/code • 69 guides
GitHubGitHub
h/github • 8 guides

GitHub Pull Requests: How and Why to Use Pull Requests

Become a PR pro in about 5 minutes.
JohnJohn John (304)
Nov 19, 2020
5 minutes
John
 
1
Posted in these interests:
h/webdev • 60 guides
h/code • 69 guides
GitHubGitHub
h/github • 8 guides
Posted in these interests:
h/webdev • 60 guides
h/code • 69 guides
GitHubGitHub
h/github • 8 guides
GitHub
Table of Contents

GitHub Pull Requests:

  1. Finding the pull requests
  2. Click “New pull request”
  3. Choose your branches
  4. Create the pull request
  5. Code review
  6. Automatically close Github issues with a pull request
 
1
In these interests
h/webdev • 60 guides
h/code • 69 guides
GitHubGitHub
h/github • 8 guides
h/webdev • 60 guides
h/code • 69 guides
GitHubGitHub
h/github • 8 guides
GitHub
Finding the pull requestsFinding the pull requests

When viewing a repository in your Github account, you should see an icon with the words “Pull requests”. Fitting, right? Click on that link to go to the pull request page.

Finding the pull requestsFinding the pull requests

When viewing a repository in your Github account, you should see an icon with the words “Pull requests”. Fitting, right? Click on that link to go to the pull request page.

Finding the pull requests

Finding the pull requests
Click "New pull request"Click "New pull request"

The pull requests page will show you existing, open pull requests. You’ll find a button at the top that says “New pull request”. Click that one.

Click "New pull request"Click "New pull request"

The pull requests page will show you existing, open pull requests. You’ll find a button at the top that says “New pull request”. Click that one.

Click “New pull request”

Click "New pull request"
Choose your branchesChoose your branches

At this point you’ll choose your branches, on the left the branch you’re merging into and on the right the branch you’re merging from. At this point, it’s assumed that you’ve pushed your branch to origin. The branch you’re merging into is often master or depending on your branching model it could be called develop. When this pull request is closed, the compare branch will be merged into the base branch.

Choose your branchesChoose your branches

At this point you’ll choose your branches, on the left the branch you’re merging into and on the right the branch you’re merging from. At this point, it’s assumed that you’ve pushed your branch to origin. The branch you’re merging into is often master or depending on your branching model it could be called develop. When this pull request is closed, the compare branch will be merged into the base branch.

Choose your branches

Choose your branches
Create the pull requestCreate the pull request

Once you’ve selected your branches, click “Create pull request”. This won’t create it but will give you the chance to leave a comment. It’s a good idea to leave a descriptive comment about what changes will be merged. It is assumed that another developer will be reviewing these changes so comments are helpful. At this point, you can scroll down to see a diff of the files changed. This is a good time to do a final review of your code to make sure it’s ready to be merged. Now click “Create pull request” again to actually create the request.

Create the pull requestCreate the pull request

Once you’ve selected your branches, click “Create pull request”. This won’t create it but will give you the chance to leave a comment. It’s a good idea to leave a descriptive comment about what changes will be merged. It is assumed that another developer will be reviewing these changes so comments are helpful. At this point, you can scroll down to see a diff of the files changed. This is a good time to do a final review of your code to make sure it’s ready to be merged. Now click “Create pull request” again to actually create the request.

Create the pull request

Create the pull request

Pull requests are a great way to review code. Once you’ve created the pull request you can send the url to someone else in the organization. They will be able to see the diff, leave comments, and eventually close and merge the pull request if everything looks good.

Pull requests are a great way to review code. Once you’ve created the pull request you can send the url to someone else in the organization. They will be able to see the diff, leave comments, and eventually close and merge the pull request if everything looks good.

Code review

Wouldn’t it be cool if Github would automatically close issues with a pull request? Well, they do! Before submitting the pull request, you should use the following language in a commit message:

Fixes #167
where 167 is the issue number this branch should close. By typing this in the commit message, issue number 167 will automatically be closed when the branch is merged into master. There are a number of different phrases you can write in the commit message to force the issue to be closed. A full list can be found here – Closing issues via commit messages.

Wouldn’t it be cool if Github would automatically close issues with a pull request? Well, they do! Before submitting the pull request, you should use the following language in a commit message:

Fixes #167
where 167 is the issue number this branch should close. By typing this in the commit message, issue number 167 will automatically be closed when the branch is merged into master. There are a number of different phrases you can write in the commit message to force the issue to be closed. A full list can be found here – Closing issues via commit messages.

Automatically close Github issues with a pull request

GitHub Codespaces is officially in beta.
AshAsh Ash (362)
Feb 4, 2021
0

Earlier this week, GitHub announced the launch of a new cloud-hosted IDE known as GitHub Codespaces. This new service is a full development environment based on Microsoft’s Visual Studio Code.

GitHub Codespaces is officially in beta.
AshAsh Ash (362)
Feb 4, 2021
0

Earlier this week, GitHub announced the launch of a new cloud-hosted IDE known as GitHub Codespaces. This new service is a full development environment based on Microsoft’s Visual Studio Code.

NEXT UP
GitHub Announces Cloud-Based IDE: GitHub Codespaces
GitHub Codespaces
GitHub Codespaces is officially in beta.
AshAsh Ash (362)
Feb 4, 2021
0
Ash Continue reading
Share this guide!
RedditEmailText
John's profile pictureJohn's profile pictureJohn
Joined in 2015 304 guides
Software Engineer and creator of howchoo.
John's profile picture
Related to this guide:
GitHub CodespacesGitHub Codespaces
GitHub Codespaces is officially in beta.
In these interests: newsgithub
Intro to Hub: Improve Your GitHub Workflow with the CLI ToolIntro to Hub: Improve Your GitHub Workflow with the CLI Tool
Hub overview Hub is a command-line tool that wraps git and provides extra functionality that makes working with GitHub easier.
In these interests: gitgithub
github package registrygithub package registry
Publishing software packages is already pretty easy, so what does GitHub’s Package Registry offer that we don’t already have?
In these interests: newsgithubgit
GitHub CodespacesGitHub Codespaces
GitHub Codespaces is officially in beta.
In these interests: newsgithub
Ash's profile pictureView guide
In these interests: newsgithub
newsgithub
Intro to Hub: Improve Your GitHub Workflow with the CLI ToolIntro to Hub: Improve Your GitHub Workflow with the CLI Tool
Hub overview Hub is a command-line tool that wraps git and provides extra functionality that makes working with GitHub easier.
In these interests: gitgithub
John's profile pictureView guide
In these interests: gitgithub
gitgithub
github package registrygithub package registry
Publishing software packages is already pretty easy, so what does GitHub’s Package Registry offer that we don’t already have?
In these interests: newsgithubgit
John's profile pictureView guide
In these interests: newsgithubgit
newsgithubgit
People also read:
A screenshot of VSCode ExtensionsA screenshot of VSCode Extensions
A screenshot of VSCode ExtensionsHow to Sync VS Code Settings Across Your Machines
Docker secretsDocker secrets
Docker secretsGetting Started with Docker Secrets
Google WorkspaceGoogle Workspace
Google Workspace10 Reasons to Upgrade to Google Workspace (G Suite)
Raspberry Pi commandsRaspberry Pi commands
Raspberry Pi commandsThe Most Common Raspberry Pi Commands (And What They Do)
How to Blog in Markdown Using GitHub and Jekyll Now
1Password vs NordPass1Password vs NordPass
We put the two password managers side by side for you!
Move in BlenderMove in Blender
Stuck in Blender? Let’s get things moving!
1Password vs NordPass1Password vs NordPass
1Password vs NordPass1Password vs NordPass: Who Wins Might Surprise You!
Upgrading macOS: Fix Invalid Active Developer Path
Move in BlenderMove in Blender
Move in BlenderHow to Move in Blender
Windows 10 IP addressWindows 10 IP address
Windows 10 IP addressHow to Find Your IP Address on Windows 10
3D printer filament3D printer filament
3D printer filament3D Printing Materials and Filament—A Comprehensive Guide
Posted in these interests:
webdevwebdev
Explore
h/webdev • 60 guides
All things web development.
codecode
Explore
h/code • 69 guides
Code is poetry — one line at a time.
GitHubGitHub
Explore
h/github • 8 guides
webdevwebdev
Explore
h/webdev • 60 guides
All things web development.
Explore
codecode
Explore
h/code • 69 guides
Code is poetry — one line at a time.
Explore
GitHubGitHub
Explore
h/github • 8 guides
Explore
Discuss this guide!
Discover interesting things!
Explore Howchoo’s most popular interests.
Explore

Follow @howchoo and learn cool things:

Are you a passionate writer? We’re hiring!

Write for Howchoo

Like what we do?

Donate

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

Write for HowchooDonate

How to Change the Duration of Notifications on MacOS

JohnJohn John (304)
Nov 19, 2020
1 minute

I enjoy Apple’s notification center, but sometimes I get way too many notifications. This can be distracting, not to mention it takes up screen real estate for quite a while. To my knowledge, there is no way to change the duration of notifications in System Preferences, but it can be done using the defaults command.

Posted in these interests:
h/mac128 guides
h/apple163 guides
h/productivity4 guides

You can open Terminal by using Finder and going to Applications > Utilities > Terminal. Or you can hit cmd + space bar and search for Terminal.

Type the following into Terminal:

defaults write com.apple.notificationcenterui bannerTime -int {duration}

Substitute {duration} for your desired duration. Since I wanted to shorten the duration of the notifications dramatically I used:

defaults write com.apple.notificationcenterui bannerTime -int 1

In order for this change to take effect you must log out and back in. Click on the “Apple” in the top left of the screen and click “Log out …”. Or you can type cmd + shift + Q.

If you’d like to test out the notification duration, you can run the following command in Terminal to display notifications from the command line:

osascript -e 'display notification "test notification!"'
JohnJohn John (304)
Nov 19, 2020
5 minutes

In this guide, we’re going to use AppleScript and a tool called osascript to display macOS notifications.

How to Change the Duration of Notifications on MacOS

JohnJohn John (304)
Nov 19, 2020
1 minute

I enjoy Apple’s notification center, but sometimes I get way too many notifications. This can be distracting, not to mention it takes up screen real estate for quite a while. To my knowledge, there is no way to change the duration of notifications in System Preferences, but it can be done using the defaults command.

Posted in these interests:
h/mac128 guides
h/apple163 guides
h/productivity4 guides

You can open Terminal by using Finder and going to Applications > Utilities > Terminal. Or you can hit cmd + space bar and search for Terminal.

Type the following into Terminal:

defaults write com.apple.notificationcenterui bannerTime -int {duration}

Substitute {duration} for your desired duration. Since I wanted to shorten the duration of the notifications dramatically I used:

defaults write com.apple.notificationcenterui bannerTime -int 1

In order for this change to take effect you must log out and back in. Click on the “Apple” in the top left of the screen and click “Log out …”. Or you can type cmd + shift + Q.

If you’d like to test out the notification duration, you can run the following command in Terminal to display notifications from the command line:

osascript -e 'display notification "test notification!"'
JohnJohn John (304)
Nov 19, 2020
5 minutes

In this guide, we’re going to use AppleScript and a tool called osascript to display macOS notifications.

 
1

How to Change the Duration of Notifications on MacOS

JohnJohn John (304)
Nov 19, 2020
1 minute

I enjoy Apple’s notification center, but sometimes I get way too many notifications. This can be distracting, not to mention it takes up screen real estate for quite a while. To my knowledge, there is no way to change the duration of notifications in System Preferences, but it can be done using the defaults command.

Posted in these interests:
h/mac128 guides
h/apple163 guides
h/productivity4 guides

You can open Terminal by using Finder and going to Applications > Utilities > Terminal. Or you can hit cmd + space bar and search for Terminal.

Type the following into Terminal:

defaults write com.apple.notificationcenterui bannerTime -int {duration}

Substitute {duration} for your desired duration. Since I wanted to shorten the duration of the notifications dramatically I used:

defaults write com.apple.notificationcenterui bannerTime -int 1

In order for this change to take effect you must log out and back in. Click on the “Apple” in the top left of the screen and click “Log out …”. Or you can type cmd + shift + Q.

If you’d like to test out the notification duration, you can run the following command in Terminal to display notifications from the command line:

osascript -e 'display notification "test notification!"'
JohnJohn John (304)
Nov 19, 2020
5 minutes

In this guide, we’re going to use AppleScript and a tool called osascript to display macOS notifications.

How to Change the Duration of Notifications on MacOS

JohnJohn John (304)
Nov 19, 2020
1 minute

I enjoy Apple’s notification center, but sometimes I get way too many notifications. This can be distracting, not to mention it takes up screen real estate for quite a while. To my knowledge, there is no way to change the duration of notifications in System Preferences, but it can be done using the defaults command.

Posted in these interests:
h/mac128 guides
h/apple163 guides
h/productivity4 guides

How to Change the Duration of Notifications on MacOS

JohnJohn John (304)
Nov 19, 2020
1 minute
John
 
1
Posted in these interests:
h/mac128 guides
h/apple163 guides
h/productivity4 guides
Posted in these interests:
h/mac128 guides
h/apple163 guides
h/productivity4 guides
Table of Contents

Jump to step:

  1. Open Terminal
  2. Using the defaults command, set your desired duration
  3. Log out and log back in
  4. Test it out
 
1
In these interests
h/mac128 guides
h/apple163 guides
h/productivity4 guides
h/mac128 guides
h/apple163 guides
h/productivity4 guides

You can open Terminal by using Finder and going to Applications > Utilities > Terminal. Or you can hit cmd + space bar and search for Terminal.

You can open Terminal by using Finder and going to Applications > Utilities > Terminal. Or you can hit cmd + space bar and search for Terminal.

Open Terminal

Type the following into Terminal:

defaults write com.apple.notificationcenterui bannerTime -int {duration}

Substitute {duration} for your desired duration. Since I wanted to shorten the duration of the notifications dramatically I used:

defaults write com.apple.notificationcenterui bannerTime -int 1

Type the following into Terminal:

defaults write com.apple.notificationcenterui bannerTime -int {duration}

Substitute {duration} for your desired duration. Since I wanted to shorten the duration of the notifications dramatically I used:

defaults write com.apple.notificationcenterui bannerTime -int 1

Using the defaults command, set your desired duration

In order for this change to take effect you must log out and back in. Click on the “Apple” in the top left of the screen and click “Log out …”. Or you can type cmd + shift + Q.

In order for this change to take effect you must log out and back in. Click on the “Apple” in the top left of the screen and click “Log out …”. Or you can type cmd + shift + Q.

Log out and log back in

If you’d like to test out the notification duration, you can run the following command in Terminal to display notifications from the command line:

osascript -e 'display notification "test notification!"'

If you’d like to test out the notification duration, you can run the following command in Terminal to display notifications from the command line:

osascript -e 'display notification "test notification!"'

Test it out

How to Change the Duration of Notifications on MacOS
JohnJohn John (304)
Nov 19, 2020
5 minutes

In this guide, we’re going to use AppleScript and a tool called osascript to display macOS notifications.

JohnJohn John (304)
Nov 19, 2020
5 minutes

In this guide, we’re going to use AppleScript and a tool called osascript to display macOS notifications.

NEXT UP
How to Display macOS Notifications from the Command Line
JohnJohn John (304)
Nov 19, 2020
5 minutes
John Continue reading
Share this guide!
RedditEmailText
John's profile pictureJohn's profile pictureJohn
Joined in 2015 304 guides
Software Engineer and creator of howchoo.
John's profile picture
Related to this guide:
How to Display macOS Notifications from the Command LineHow to Display macOS Notifications from the Command Line
In this guide, we’re going to use AppleScript and a tool called osascript to display macOS notifications.
In these interests: macapple
no notificationsno notifications
Have you ever heard that annoying ding, notifying you about something running in the background on your computer?
In these interests: windowspc
Open a .rar file in MacOSOpen a .rar file in MacOS
Use “The Unarchiver” to unzip a .rar file for free.
In these interests: macmacos
How to Display macOS Notifications from the Command LineHow to Display macOS Notifications from the Command Line
In this guide, we’re going to use AppleScript and a tool called osascript to display macOS notifications.
In these interests: macapple
John's profile pictureView guide
In these interests: macapple
macapple
no notificationsno notifications
Have you ever heard that annoying ding, notifying you about something running in the background on your computer?
In these interests: windowspc
Jamie's profile pictureView guide
In these interests: windowspc
windowspc
Open a .rar file in MacOSOpen a .rar file in MacOS
Use “The Unarchiver” to unzip a .rar file for free.
In these interests: macmacos
Michael's profile pictureView guide
In these interests: macmacos
macmacos
People also read:
How to Create an Emoji Alias on Slack
JavaScript for loops
Proper American Flag DisposalProper American Flag Disposal
Proper American Flag DisposalHow to properly dispose of a worn or damaged American flag
Python Dictionary Comprehension (With Examples)
How to Scan a QR Code on an iPhone or iPadHow to Scan a QR Code on an iPhone or iPad
How to Scan a QR Code on an iPhone or iPadHow to Scan a QR Code on an iPhone or iPad
Uninstall any unwanted Android apps.
How to Save in InDesign as a PDFHow to Save in InDesign as a PDF
Hint: you technically aren’t looking to save but to export.
Gatsby logoGatsby logo
No more jamming everything in your Layout component.
How to Delete Apps on Any Android Device
How to Save in InDesign as a PDFHow to Save in InDesign as a PDF
How to Save in InDesign as a PDFHow to Save in InDesign as a PDF
Gatsby logoGatsby logo
Gatsby logoStore Gatsby GraphQL Fragments in Their Own External Files
messenger kids codesmessenger kids codes
messenger kids codesHow to Add Friends Using Codes on Messenger Kids
How to Disable Notifications in Chrome
Posted in these interests:
macmac
Explore
h/mac 128 guides
appleapple
Explore
h/apple 163 guides
Apple Computers is an American computer and consumer electronics company founded by Steve Jobs and Steve Wozniak.
productivityproductivity
Explore
h/productivity 4 guides
macmac
Explore
h/mac 128 guides
Explore
appleapple
Explore
h/apple 163 guides
Apple Computers is an American computer and consumer electronics company founded by Steve Jobs and Steve Wozniak.
Explore
productivityproductivity
Explore
h/productivity 4 guides
Explore
Discuss this guide!
Discover interesting things!
Explore Howchoo’s most popular interests.
Explore

Follow @howchoo and learn cool things:

Are you a passionate writer? We’re hiring!

Write for Howchoo

Like what we do?

Donate

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

Write for HowchooDonate

Retro Weather Channel on the Raspberry Pi

Today’s weather—yesterday’s vibes.
AshAsh Ash (362)
Nov 19, 2020
0

Let’s face it—checking the weather is easier than ever. If it’s not on your phone’s lock screen, there’s probably a device nearby you could ask for local weather information. But what if there was a way to take things back to the good ol’ days, when weather data was worthy of its own full-time channel on the TV?

Maker Probnot on Reddit took this to heart with this awesome weather channel Pi project! This Raspberry Pi is programmed to recreate the old weather channel that ran in Winnepeg back in the 1990s.

Watch the video:

Raspberry Pi 3Raspberry Pi 3Raspberry Pi 3 ×1

Howchoo is reader-supported. As an Amazon Associate, we may earn a small affiliate commission at no cost to you when you buy through our links.

If you want to peek behind the curtains, Probnot posted the code on GitHub (and adds that this code was loosely put together—please be gentle). The script pulls current weather information from Environment Canada and formats the data into a vintage-looking display.

In the video example, the Raspberry Pi display is output to an old CRT. According to Probnot, this was accomplished with RF modulators connected to the cable in his house. The number shown in the corner is the actual UHF channel.

We really like this project and definitely see the appeal. Is it practical? In a Raspberry Pi project sort of way. Follow Probnot on Youtube and Reddit for more project updates.

Removing the cold inhuman experience of a silent Roomba.
AshAsh Ash (362)
Nov 19, 2020
0

Youtuber and tech maker Michael Reeves had way too much fun with this screaming Roomba project.

Follow @howchoo and learn cool things:

Are you a passionate writer? We’re hiring!

Write for Howchoo

Like what we do?

Donate

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

Nov 19, 2020
h/docker12 guides
h/docker12 guides
Nov 19, 2020
10 minutes
John's profile pictureJohn's profile pictureJohn
Joined in 2015 304 guides
Software Engineer and creator of howchoo.
Docker secrets is a secrets management tool designed for use with Docker Swarm. And of course, Docker Swarm refers to the cluster management and orchestration features built into the Docker Engine.
In these interests: dockersecuritydevops
Start mining Bitcoin in 5 minutes
In these interests: bitcoincryptocurrencydocker
If you’ve been experimenting with Docker, you’ve probably discovered that each time you restart a container the data is gone.
In these interests: dockercodewebdev
Obviously we’d call this “Supernetes”
Explore
h/docker 12 guides
Docker is an open-source that aims to automate the deployment of applications inside containers.

How to encrypt files on Mac OS X 10.9

JohnJohn John (304)
Nov 19, 2020
10 minutes

This guide was written for OS X 10.9. For an updated version of this guide click here.

There are plenty of reasons you will want to encrypt files on your personal computer. There is a lot of software available that can do this for you, but I’m going to show you how to do it using tools that come preinstalled on OS X.

Posted in these interests:
h/osx • 35 guides
h/apple • 163 guides
h/mac • 128 guides
Open Disk UtilityOpen Disk Utility
 cmd + space bar 

Hit command + space bar to open Spotlight, and search for “Disk Utility”. Once you find it, select it and hit enter.

Click on New ImageClick on New Image

On the row of icons, click the icon that says “New Image”.

Configure your new disk imageConfigure your new disk image

This step will allow you to create a new disk image. Think of it like a virtual USB thumb drive. Once you create it you will be able to mount it (plug it in) and unmount (eject) it, but it will be stored as a “dmg” (disk image) file. Under “Save As” put the file name that you would like the disk image to be called. If you type “secure” the file will be called “secure.dmg”. By default the disk image will be saved in your Documents folder. You are free to change this to another directory of your choice.

Under the “Name” input, type whatever you would like the disk image to be called once its mounted. This will help you to identify it in Finder. For simplicity, I recommend calling it the same thing that you call the disk image file.

Add encryption to this disk imageAdd encryption to this disk image

Under “Encryption” change the option from “none” to either of the options – 128 or 256-bit AES.

Once you click create you will be prompted to give and verify a password. Use this guide to learn how to create a secure password. This will effectively create your new encrypted disk image.

Add files to your disk imageAdd files to your disk image

Just like a USB thumb drive you will need to “plug it in” before you can save files on it. To do this simply navigate to the directory where it is saved. By default it will be located in your Documents folder. Double click on the disk image file, and enter your password when prompted. Finder will open and the encrypted disk will be selected. You can start dropping files into this directory.

Eject the disk imageEject the disk image

While the disk image is mounted anyone will have access to these files. Once you are finished adding files you will want to secure it by simply ejecting the disk image. This means that anyone who wants to mount this disk image and access the files will need to enter the password you’ve chosen. Anyone who finds the dmg file will be out of luck because the entire thing will be encrypted.

JohnJohn John (304)
Nov 19, 2020
1 minute

This short guide will show you how to enable php.ini on Mac OS X 10.8.X.

How to encrypt files on Mac OS X 10.9

JohnJohn John (304)
Nov 19, 2020
10 minutes

This guide was written for OS X 10.9. For an updated version of this guide click here.

There are plenty of reasons you will want to encrypt files on your personal computer. There is a lot of software available that can do this for you, but I’m going to show you how to do it using tools that come preinstalled on OS X.

Posted in these interests:
h/osx • 35 guides
h/apple • 163 guides
h/mac • 128 guides
Open Disk UtilityOpen Disk Utility
 cmd + space bar 

Hit command + space bar to open Spotlight, and search for “Disk Utility”. Once you find it, select it and hit enter.

Click on New ImageClick on New Image

On the row of icons, click the icon that says “New Image”.

Configure your new disk imageConfigure your new disk image

This step will allow you to create a new disk image. Think of it like a virtual USB thumb drive. Once you create it you will be able to mount it (plug it in) and unmount (eject) it, but it will be stored as a “dmg” (disk image) file. Under “Save As” put the file name that you would like the disk image to be called. If you type “secure” the file will be called “secure.dmg”. By default the disk image will be saved in your Documents folder. You are free to change this to another directory of your choice.

Under the “Name” input, type whatever you would like the disk image to be called once its mounted. This will help you to identify it in Finder. For simplicity, I recommend calling it the same thing that you call the disk image file.

Add encryption to this disk imageAdd encryption to this disk image

Under “Encryption” change the option from “none” to either of the options – 128 or 256-bit AES.

Once you click create you will be prompted to give and verify a password. Use this guide to learn how to create a secure password. This will effectively create your new encrypted disk image.

Add files to your disk imageAdd files to your disk image

Just like a USB thumb drive you will need to “plug it in” before you can save files on it. To do this simply navigate to the directory where it is saved. By default it will be located in your Documents folder. Double click on the disk image file, and enter your password when prompted. Finder will open and the encrypted disk will be selected. You can start dropping files into this directory.

Eject the disk imageEject the disk image

While the disk image is mounted anyone will have access to these files. Once you are finished adding files you will want to secure it by simply ejecting the disk image. This means that anyone who wants to mount this disk image and access the files will need to enter the password you’ve chosen. Anyone who finds the dmg file will be out of luck because the entire thing will be encrypted.

JohnJohn John (304)
Nov 19, 2020
1 minute

This short guide will show you how to enable php.ini on Mac OS X 10.8.X.

 
1

How to encrypt files on Mac OS X 10.9

JohnJohn John (304)
Nov 19, 2020
10 minutes

This guide was written for OS X 10.9. For an updated version of this guide click here.

There are plenty of reasons you will want to encrypt files on your personal computer. There is a lot of software available that can do this for you, but I’m going to show you how to do it using tools that come preinstalled on OS X.

Posted in these interests:
h/osx • 35 guides
h/apple • 163 guides
h/mac • 128 guides
Open Disk UtilityOpen Disk Utility
 cmd + space bar 

Hit command + space bar to open Spotlight, and search for “Disk Utility”. Once you find it, select it and hit enter.

Click on New ImageClick on New Image

On the row of icons, click the icon that says “New Image”.

Configure your new disk imageConfigure your new disk image

This step will allow you to create a new disk image. Think of it like a virtual USB thumb drive. Once you create it you will be able to mount it (plug it in) and unmount (eject) it, but it will be stored as a “dmg” (disk image) file. Under “Save As” put the file name that you would like the disk image to be called. If you type “secure” the file will be called “secure.dmg”. By default the disk image will be saved in your Documents folder. You are free to change this to another directory of your choice.

Under the “Name” input, type whatever you would like the disk image to be called once its mounted. This will help you to identify it in Finder. For simplicity, I recommend calling it the same thing that you call the disk image file.

Add encryption to this disk imageAdd encryption to this disk image

Under “Encryption” change the option from “none” to either of the options – 128 or 256-bit AES.

Once you click create you will be prompted to give and verify a password. Use this guide to learn how to create a secure password. This will effectively create your new encrypted disk image.

Add files to your disk imageAdd files to your disk image

Just like a USB thumb drive you will need to “plug it in” before you can save files on it. To do this simply navigate to the directory where it is saved. By default it will be located in your Documents folder. Double click on the disk image file, and enter your password when prompted. Finder will open and the encrypted disk will be selected. You can start dropping files into this directory.

Eject the disk imageEject the disk image

While the disk image is mounted anyone will have access to these files. Once you are finished adding files you will want to secure it by simply ejecting the disk image. This means that anyone who wants to mount this disk image and access the files will need to enter the password you’ve chosen. Anyone who finds the dmg file will be out of luck because the entire thing will be encrypted.

JohnJohn John (304)
Nov 19, 2020
1 minute

This short guide will show you how to enable php.ini on Mac OS X 10.8.X.

How to encrypt files on Mac OS X 10.9

JohnJohn John (304)
Nov 19, 2020
10 minutes

This guide was written for OS X 10.9. For an updated version of this guide click here.

There are plenty of reasons you will want to encrypt files on your personal computer. There is a lot of software available that can do this for you, but I’m going to show you how to do it using tools that come preinstalled on OS X.

Posted in these interests:
h/osx • 35 guides
h/apple • 163 guides
h/mac • 128 guides

How to encrypt files on Mac OS X 10.9

JohnJohn John (304)
Nov 19, 2020
10 minutes
John
 
1
How to Encrypt Files on macOS
Posted in these interests:
h/osx • 35 guides
h/apple • 163 guides
h/mac • 128 guides
Posted in these interests:
h/osx • 35 guides
h/apple • 163 guides
h/mac • 128 guides
Table of Contents

Jump to step:

  1. Open Disk Utility
  2. Click on New Image
  3. Configure your new disk image
  4. Name the disk image
  5. Add encryption to this disk image
  6. Click Create and enter a secure password
  7. Add files to your disk image
  8. Eject the disk image
  9. Show all 8
 
1
In these interests
h/osx • 35 guides
h/apple • 163 guides
h/mac • 128 guides
h/osx • 35 guides
h/apple • 163 guides
h/mac • 128 guides
Open Disk UtilityOpen Disk Utility
 cmd + space bar 

Hit command + space bar to open Spotlight, and search for “Disk Utility”. Once you find it, select it and hit enter.

Open Disk UtilityOpen Disk Utility
 cmd + space bar 

Hit command + space bar to open Spotlight, and search for “Disk Utility”. Once you find it, select it and hit enter.

Open Disk Utility

Open Disk Utility
Click on New ImageClick on New Image

On the row of icons, click the icon that says “New Image”.

Click on New ImageClick on New Image

On the row of icons, click the icon that says “New Image”.

Click on New Image

Click on New Image
Configure your new disk imageConfigure your new disk image

This step will allow you to create a new disk image. Think of it like a virtual USB thumb drive. Once you create it you will be able to mount it (plug it in) and unmount (eject) it, but it will be stored as a “dmg” (disk image) file. Under “Save As” put the file name that you would like the disk image to be called. If you type “secure” the file will be called “secure.dmg”. By default the disk image will be saved in your Documents folder. You are free to change this to another directory of your choice.

Configure your new disk imageConfigure your new disk image

This step will allow you to create a new disk image. Think of it like a virtual USB thumb drive. Once you create it you will be able to mount it (plug it in) and unmount (eject) it, but it will be stored as a “dmg” (disk image) file. Under “Save As” put the file name that you would like the disk image to be called. If you type “secure” the file will be called “secure.dmg”. By default the disk image will be saved in your Documents folder. You are free to change this to another directory of your choice.

Configure your new disk image

Configure your new disk image

Under the “Name” input, type whatever you would like the disk image to be called once its mounted. This will help you to identify it in Finder. For simplicity, I recommend calling it the same thing that you call the disk image file.

Under the “Name” input, type whatever you would like the disk image to be called once its mounted. This will help you to identify it in Finder. For simplicity, I recommend calling it the same thing that you call the disk image file.

Name the disk image

Add encryption to this disk imageAdd encryption to this disk image

Under “Encryption” change the option from “none” to either of the options – 128 or 256-bit AES.

Add encryption to this disk imageAdd encryption to this disk image

Under “Encryption” change the option from “none” to either of the options – 128 or 256-bit AES.

Add encryption to this disk image

Add encryption to this disk image

Once you click create you will be prompted to give and verify a password. Use this guide to learn how to create a secure password. This will effectively create your new encrypted disk image.

Once you click create you will be prompted to give and verify a password. Use this guide to learn how to create a secure password. This will effectively create your new encrypted disk image.

Click Create and enter a secure password

How to Generate a Random, Secure Password
Add files to your disk imageAdd files to your disk image

Just like a USB thumb drive you will need to “plug it in” before you can save files on it. To do this simply navigate to the directory where it is saved. By default it will be located in your Documents folder. Double click on the disk image file, and enter your password when prompted. Finder will open and the encrypted disk will be selected. You can start dropping files into this directory.

Add files to your disk imageAdd files to your disk image

Just like a USB thumb drive you will need to “plug it in” before you can save files on it. To do this simply navigate to the directory where it is saved. By default it will be located in your Documents folder. Double click on the disk image file, and enter your password when prompted. Finder will open and the encrypted disk will be selected. You can start dropping files into this directory.

Add files to your disk image

Add files to your disk image
Eject the disk imageEject the disk image

While the disk image is mounted anyone will have access to these files. Once you are finished adding files you will want to secure it by simply ejecting the disk image. This means that anyone who wants to mount this disk image and access the files will need to enter the password you’ve chosen. Anyone who finds the dmg file will be out of luck because the entire thing will be encrypted.

Eject the disk imageEject the disk image

While the disk image is mounted anyone will have access to these files. Once you are finished adding files you will want to secure it by simply ejecting the disk image. This means that anyone who wants to mount this disk image and access the files will need to enter the password you’ve chosen. Anyone who finds the dmg file will be out of luck because the entire thing will be encrypted.

Eject the disk image

Eject the disk image
JohnJohn John (304)
Nov 19, 2020
1 minute

This short guide will show you how to enable php.ini on Mac OS X 10.8.X.

JohnJohn John (304)
Nov 19, 2020
1 minute

This short guide will show you how to enable php.ini on Mac OS X 10.8.X.

NEXT UP
How to Enable php.ini on Mac OS X 10.8.X
JohnJohn John (304)
Nov 19, 2020
1 minute
John Continue reading
Share this guide!
RedditEmailText
John's profile pictureJohn's profile pictureJohn
Joined in 2015 304 guides
Software Engineer and creator of howchoo.
John's profile picture
Related to this guide:
How to Enable php.ini on Mac OS X 10.8.XHow to Enable php.ini on Mac OS X 10.8.X
This short guide will show you how to enable php.ini on Mac OS X 10.8.X.
In these interests: osxmacapple
How to install ctrlp fuzzy finder for vimHow to install ctrlp fuzzy finder for vim
Using a fuzzy finder for vim is life changing. I’ve used two different fuzzy finders: command T and ctrlp.
In these interests: vim
Double-Click the Menu Bar to Minimize an Application in macOSDouble-Click the Menu Bar to Minimize an Application in macOS
You can set up your Apple computer so that when you double-click the menu bar it minimizes the application. This is a huge time saver and is OS X does not do this by default.
In these interests: osxmacapple
How to Enable php.ini on Mac OS X 10.8.XHow to Enable php.ini on Mac OS X 10.8.X
This short guide will show you how to enable php.ini on Mac OS X 10.8.X.
In these interests: osxmacapple
John's profile pictureView guide
In these interests: osxmacapple
osxmacapple
How to install ctrlp fuzzy finder for vimHow to install ctrlp fuzzy finder for vim
Using a fuzzy finder for vim is life changing. I’ve used two different fuzzy finders: command T and ctrlp.
In these interests: vim
John's profile pictureView guide
In these interests: vim
vim
Double-Click the Menu Bar to Minimize an Application in macOSDouble-Click the Menu Bar to Minimize an Application in macOS
You can set up your Apple computer so that when you double-click the menu bar it minimizes the application. This is a huge time saver and is OS X does not do this by default.
In these interests: osxmacapple
Zach's profile pictureView guide
In these interests: osxmacapple
osxmacapple
People also read:
How to enable the dashboard in OS X El Capitan
Make a Bootable USB Drive on Mac
Backing up Raspberry Pi SD cardBacking up Raspberry Pi SD card
Backing up Raspberry Pi SD cardHow to Back Up and Restore Your Raspberry Pi SD Card on Mac
TimeMachine macOSTimeMachine macOS
TimeMachine macOSHow to Disable Local Time Machine Backups in macOS
How to Set Up a LAMP server in macOS
How to Change Your Mac Computer’s Bluetooth Name
How to download apps from anywhere in macOS Sierra
How to uninstall an application using an uninstaller on Mac OS X
raspberry pi NOOBsraspberry pi NOOBs
raspberry pi NOOBsRaspberry Pi NOOBS: How to Set Up, Configure, and Use NOOBS
How to Set Up Linux on Your PC Using a Virtual Machine
Posted in these interests:
osxosx
Explore
h/osx • 35 guides
OS X is a series of Unix-based operating systems developed by Apple, Inc. The first public beta, called Kodiak, appeared in 2000.
appleapple
Explore
h/apple • 163 guides
Apple Computers is an American computer and consumer electronics company founded by Steve Jobs and Steve Wozniak.
macmac
Explore
h/mac • 128 guides
securitysecurity
Explore
h/security • 45 guides
cryptographycryptography
Explore
h/cryptography • 3 guides
osxosx
Explore
h/osx • 35 guides
OS X is a series of Unix-based operating systems developed by Apple, Inc. The first public beta, called Kodiak, appeared in 2000.
Explore
appleapple
Explore
h/apple • 163 guides
Apple Computers is an American computer and consumer electronics company founded by Steve Jobs and Steve Wozniak.
Explore
macmac
Explore
h/mac • 128 guides
Explore
securitysecurity
Explore
h/security • 45 guides
Explore
cryptographycryptography
Explore
h/cryptography • 3 guides
Explore
Discuss this guide!
Discover interesting things!
Explore Howchoo’s most popular interests.
Explore

Follow @howchoo and learn cool things:

Are you a passionate writer? We’re hiring!

Write for Howchoo

Like what we do?

Donate

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

Write for HowchooDonate

How to Log in to a Time Warner Router

DayneDayne Dayne (57)
Nov 19, 2020
5 minutes

There are many reasons you might want to access your Time Warner router. For instance, you may want to change your password or set up port forwarding for a nerdy project you are working on.

Time Warner routerTime Warner routerTime Warner router ×1
Computer, tablet, or mobile device ×1

Howchoo is reader-supported. When you buy through links on our site, we may earn a small affiliate commission at no cost to you.

This can be a wired or wifi connection.

Or click here: http://192.168.0.1. This is the router’s gateway and it will automatically bring up a log in screen.

Username: admin Password: password

Now you’re logged in!

You can change your password by click “Change Password” at the top left of the admin panel.

Hard resets for hard network problems.
AshAsh Ash (340)
Nov 19, 2020
5 minutes

In many cases, a simple reset will resolve many network issues or hangups with your modem or router. There are different ways to reset your device, some of which are more intense than others.

Follow @howchoo and learn cool things:

Are you a passionate writer? We’re hiring!

Write for Howchoo

Like what we do?

Donate

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.