<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Steve</title>
    <description>The latest articles on Forem by Steve (@stvbyr).</description>
    <link>https://forem.com/stvbyr</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F627075%2F12a4b53e-e5f8-416f-a8c8-8b3067d7484d.png</url>
      <title>Forem: Steve</title>
      <link>https://forem.com/stvbyr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/stvbyr"/>
    <language>en</language>
    <item>
      <title>Sync Obsidian Vault to a Synology Home Server With Git</title>
      <dc:creator>Steve</dc:creator>
      <pubDate>Mon, 02 May 2022 12:56:21 +0000</pubDate>
      <link>https://forem.com/stvbyr/sync-obsidian-vault-to-a-synology-home-server-with-git-a97</link>
      <guid>https://forem.com/stvbyr/sync-obsidian-vault-to-a-synology-home-server-with-git-a97</guid>
      <description>&lt;p&gt;In my previous post I showed you how you can &lt;br&gt;
&lt;a href="https://dev.to/stvbyr/use-multiple-obsidianmd-config-folders-and-sync-with-github-27no"&gt;use multiple Obsidian config&lt;br&gt;
folders and sync them with github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;While this is an easy way to manage your vault you may want to store and manage your data by yourself. And there are valid reasons for that.&lt;/p&gt;

&lt;p&gt;This is a good solution if you wanna manage personal information that you don't feel like sharing on a public platform.&lt;/p&gt;
&lt;h2&gt;
  
  
  Goals
&lt;/h2&gt;

&lt;p&gt;At the End of this post we will have the following setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sync our Obsidian vault automatically with the &lt;a href="https://github.com/denolehov/Obsidian-git"&gt;Obsidian Git plugin&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Use a shared folder on the Synology that holds git repositories&lt;/li&gt;
&lt;li&gt;Login keyless so that the Obsidian plugin can be automated (also you can login with that user without inputting passwords)&lt;/li&gt;
&lt;li&gt;Use a non-admin user for security reasons (keyless auth is a security risk if not restricted properly)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Make a backup of your Synology (full backup)&lt;/li&gt;
&lt;li&gt;Basic knowledge in git

&lt;ul&gt;
&lt;li&gt;You don't need to know the ins and outs of git but I expect you to know what a .gitignore does, how to clone and how to use basic git commands&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Synology with DSM 7 installed (could work for DSM 6 but not tested)

&lt;ul&gt;
&lt;li&gt;Git-Server needs to be installed&lt;/li&gt;
&lt;li&gt;Admin SSH access to the Synology&lt;/li&gt;
&lt;li&gt;(optional) DDNS access so you can sync from anywhere&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Obsidian installed on at least one device

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/denolehov/Obsidian-git"&gt;Obsidian Git plugin&lt;/a&gt; installed &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;p&gt;To reach our goals we need to configure the Synology and our client. We will start with the Synology.&lt;/p&gt;
&lt;h3&gt;
  
  
  Synology
&lt;/h3&gt;

&lt;p&gt;Login to the web interface of your Synology.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Create a shared folder for git repositories
&lt;/h4&gt;

&lt;p&gt;Navigate to &lt;code&gt;Control Panel &amp;gt; Shared Folders &amp;gt; Create&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Choose a name and description for the folder and the location where you want the folder to live. I named mine &lt;code&gt;git-repos&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Skip Encryption.&lt;/p&gt;

&lt;p&gt;Confirm Settings. &lt;/p&gt;

&lt;p&gt;Skip "Configure user permissions" for now. We come to that in the next step.&lt;/p&gt;
&lt;h4&gt;
  
  
  2. Create a user that will be able to sync via ssh
&lt;/h4&gt;

&lt;p&gt;Navigate to &lt;code&gt;Control Panel &amp;gt; User &amp;amp; Group &amp;gt; User &amp;gt; Create&lt;/code&gt;. I named mine &lt;code&gt;gitworker&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Under "User Groups" choose the default "users" group. We don't want this user&lt;br&gt;
to be in any group so that we can specify the rights manually.&lt;/p&gt;

&lt;p&gt;Under "Permissions" check Read/Write for the created &lt;code&gt;git-repos&lt;/code&gt; folder. All&lt;br&gt;
other folders should not be accessible.&lt;/p&gt;
&lt;h4&gt;
  
  
  3. Enable SSH Service
&lt;/h4&gt;

&lt;p&gt;Navigate to &lt;code&gt;Control Panel &amp;gt; Terminal &amp;amp; SNMP&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Check "Enable SSH service" and change the port to a non reserved port &lt;br&gt;
(for example 51289, this is optional but advised). &lt;/p&gt;

&lt;p&gt;This port is then always used to ssh into your Synology.&lt;/p&gt;
&lt;h4&gt;
  
  
  4. Enable user to work with SSH
&lt;/h4&gt;

&lt;p&gt;By default, Synology disables all ssh access to non-admin users. &lt;br&gt;
It even resets the login shell config periodically. So changes&lt;br&gt;
to &lt;code&gt;/etc/passwd&lt;/code&gt; will be reset.&lt;/p&gt;

&lt;p&gt;I used &lt;a href="https://andidittrich.de/2016/03/howto-re-enable-scpssh-login-on-Synology-dsm-6-0-for-non-admin-users.html"&gt;this blog post by Andi Dittrich&lt;/a&gt; to solve the problem. It's a little dated but still works for DSM 7.0.&lt;/p&gt;

&lt;p&gt;In short: we need to use a scheduled task to periodically set the login shell&lt;br&gt;
for our gituser.&lt;/p&gt;

&lt;p&gt;Login to your Synology with the admin user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="o"&gt;{&lt;/span&gt;adminuser&lt;span class="o"&gt;}&lt;/span&gt;@&lt;span class="o"&gt;{&lt;/span&gt;Synology&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;port&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create the scheduled script for your gituser.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /volume&lt;span class="o"&gt;{&lt;/span&gt;X&lt;span class="o"&gt;}&lt;/span&gt;/homes/&lt;span class="o"&gt;{&lt;/span&gt;adminuser&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;touch &lt;/span&gt;enable-ssh-login.sh &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; vi enable-ssh-login.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Press &lt;code&gt;i&lt;/code&gt; to get into insert mode and paste the following content.&lt;br&gt;
This script uses the &lt;code&gt;awk&lt;/code&gt; command and sets the login shell&lt;br&gt;
for our created gituser to &lt;code&gt;/bin/sh&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
/usr/bin/awk &lt;span class="nt"&gt;-i&lt;/span&gt; inplace &lt;span class="nt"&gt;-F&lt;/span&gt;: &lt;span class="s1"&gt;'BEGIN{OFS=":"}/^gitworker\:/{gsub(/.*/,"/bin/sh",$7)}1'&lt;/span&gt; /etc/passwd
&lt;span class="nb"&gt;exit &lt;/span&gt;0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Press &lt;code&gt;Esc&lt;/code&gt; to go back to command mode to save &amp;amp; close with &lt;code&gt;:wq&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Go back to the web backend and navigate to&lt;br&gt;
&lt;code&gt;Control Panel &amp;gt; Task Scheduler &amp;gt; Create &amp;gt; Scheduled Task &amp;gt; User-defined script&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Under General: Enter a suitable task name. Choose your admin user as executor.&lt;/p&gt;

&lt;p&gt;Under Schedule: Run on the following days "Daily". Frequency "Every 5 minutes".&lt;/p&gt;

&lt;p&gt;Under Task Settings: Run commands &amp;gt; User-defined script &lt;code&gt;/volume{X}/homes/{adminuser}/enable-ssh-logins.sh&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  5. Configure SSH to work with keyless auth
&lt;/h4&gt;

&lt;p&gt;Read this excellent &lt;a href="https://blog.aaronlenoir.com/2018/05/06/ssh-into-Synology-nas-with-ssh-key/"&gt;tutorial by Aaron Lenoir&lt;/a&gt; if you want to know more. Essential parts are "Enable Public Key Authentication":&lt;/p&gt;

&lt;p&gt;Login to your Synology with ssh. Use the admin user.&lt;/p&gt;

&lt;p&gt;Open the sshd_config. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Be careful though as this file configures ssh and you can totally ruin your Synology if you change the wrong things. If you didn't make a backup do it definitely now!&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;vi /etc/ssh/sshd_config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find the following lines and uncomment them (remove the &lt;code&gt;#&lt;/code&gt;). This will enable public key authentication for your Synology.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#RSAAuthentication yes&lt;/span&gt;
&lt;span class="c"&gt;#PubkeyAuthentication yes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart the ssh service (use systemctl as synoservicectl is not available anymore)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl reload sshd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Client/Obsidian side
&lt;/h3&gt;

&lt;p&gt;Start a terminal session on your client.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Generate a keyless SSL Key-Pair for the client
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-keygen &lt;span class="nt"&gt;-t&lt;/span&gt; ed25519 &lt;span class="nt"&gt;-f&lt;/span&gt; ed25519_keyless
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure to leave password blank to enable keyless auth&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Add local public key to authorized_keys on your Synology
&lt;/h4&gt;

&lt;p&gt;To authenticate and encrypt the connection to the Synology you have to add your&lt;br&gt;
local keyless public key to your Synology.&lt;/p&gt;

&lt;p&gt;Get the keyless public key (Linux, Mac)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; ~/.ssh/ed25519_keyless.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On windows (powershell)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="kr"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;~\.ssh\ed25519_keyless.pub&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The string should start with "ssh-ed25519". Copy the whole content. &lt;/p&gt;

&lt;p&gt;Login to your Synology with ssh. Use the admin user again.&lt;/p&gt;

&lt;p&gt;Then open the &lt;code&gt;authorized_keys&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="o"&gt;{&lt;/span&gt;adminuser&lt;span class="o"&gt;}&lt;/span&gt;@&lt;span class="o"&gt;{&lt;/span&gt;Synology&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;port&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;vi /volume&lt;span class="o"&gt;{&lt;/span&gt;X&lt;span class="o"&gt;}&lt;/span&gt;/homes/gitworker/.ssh/authorized_keys
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Press &lt;code&gt;i&lt;/code&gt; to get into edit mode.&lt;/p&gt;

&lt;p&gt;Paste the public key. If you already have keys in there use a new line to paste the key. &lt;/p&gt;

&lt;p&gt;Press &lt;code&gt;Esc&lt;/code&gt; to leave edit mode and save with &lt;code&gt;:wq&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. SSH Login with gitworker
&lt;/h4&gt;

&lt;p&gt;Logout and Login back in but now with the gitworker user&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh gitworker@&lt;span class="o"&gt;{&lt;/span&gt;Synology&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;port&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you completed all the previous tasks you should now be logged in without seeing a login prompt.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Making your life easier (optional)
&lt;/h4&gt;

&lt;p&gt;It is tedious to always input the username and the port. It would be nice if we could make the gitworker the standard login.&lt;/p&gt;

&lt;p&gt;It turns out we can. Create a &lt;code&gt;config&lt;/code&gt; file in the &lt;code&gt;.ssh&lt;/code&gt; directory with the following content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User gitworker
Port {port}
IdentityFile ~/.ssh/ed25519_keyless
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows you to just &lt;code&gt;ssh {Synology}&lt;/code&gt; and you're logged in!&lt;/p&gt;

&lt;p&gt;You can still use other users, ports, etc. to log in if you specify them. The ssh binary will figure out what mechanism to use for login.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. Creating the repository
&lt;/h4&gt;

&lt;p&gt;Now you can ssh as gitworker and create your Obsidian vault on the server. &lt;/p&gt;

&lt;p&gt;I am a bit lazy and don't want to copy paste everything, so use this tutorial for the &lt;a href="https://kb.Synology.com/en-global/DSM/help/Git/git?version=7"&gt;Synology Git Server&lt;/a&gt; to create your repository and clone it to your client.&lt;/p&gt;

&lt;p&gt;The repository has to be created within the new &lt;code&gt;git-repos&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;The clone command should look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone ssh://gitworker@&lt;span class="o"&gt;{&lt;/span&gt;Synology&lt;span class="o"&gt;}&lt;/span&gt;:&lt;span class="o"&gt;{&lt;/span&gt;port&lt;span class="o"&gt;}&lt;/span&gt;/volume&lt;span class="o"&gt;{&lt;/span&gt;X&lt;span class="o"&gt;}&lt;/span&gt;/git-repos/second-brain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The clone should work without a password. As well as all other git commands such as push or pull. This important because otherwise the obsidian plugin cannot be automated.&lt;/p&gt;

&lt;h4&gt;
  
  
  6. Setting up sync with Obsidian Git
&lt;/h4&gt;

&lt;p&gt;Follow my tutorial on how to &lt;a href="https://dev.to/stvbyr/use-multiple-obsidianmd-config-folders-and-sync-with-github-27no"&gt;use multiple Obsidian config&lt;br&gt;
folders and sync them with github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The main difference between using github and your own repos is the setup of the git repository. Everything else is the same for both approaches.&lt;/p&gt;

&lt;p&gt;You can skip the personal access token generation because we are already able to access our synology via ssh at this point.&lt;/p&gt;

&lt;p&gt;In that tutorial we also setup multiple config folders so that you can use your vault on multiple devices with different configurations. If you don't want such a setup you can remove the &lt;code&gt;.obsidian&lt;/code&gt; folder from the &lt;code&gt;.gitignore&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;It's a little bit of work but now you can host your own Obsidian vault on your Synology.&lt;/p&gt;

&lt;p&gt;Bonus: you're also able to host some git projects on your Synology now. The gitworker has access to the git-repos folder and can add more repositories if required.&lt;/p&gt;

</description>
      <category>obsidian</category>
      <category>synology</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Use Multiple Obsidian.md Config Folders And Sync With Github</title>
      <dc:creator>Steve</dc:creator>
      <pubDate>Sat, 08 Jan 2022 10:43:49 +0000</pubDate>
      <link>https://forem.com/stvbyr/use-multiple-obsidianmd-config-folders-and-sync-with-github-27no</link>
      <guid>https://forem.com/stvbyr/use-multiple-obsidianmd-config-folders-and-sync-with-github-27no</guid>
      <description>&lt;p&gt;&lt;a href="https://obsidian.md/" rel="noopener noreferrer"&gt;Obsidian&lt;/a&gt; is a great tool for collecting knowledge and connecting ideas together. I use it on many devices.&lt;/p&gt;

&lt;p&gt;However, I do not use the same configurations or plugins on all devices. Simply because some plugins just don't work on all devices. I would have to configure the app over and over again for every device that I use.&lt;/p&gt;

&lt;p&gt;A simple way to manage these is by using a Github repository (either public or private).&lt;/p&gt;

&lt;p&gt;The following guide was made on a desktop device. For IPhone users the workflow is a bit different. You can use this guide "&lt;a href="https://forum.obsidian.md/t/mobile-setting-up-ios-git-based-syncing-with-mobile-app-using-working-copy/16499" rel="noopener noreferrer"&gt;{Mobile} Setting up iOS git-based syncing with mobile app (using Working Copy)&lt;/a&gt;" to make it work. I could not test any android phones but I assume you can do something similar maybe with a different git client.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Git Repository
&lt;/h2&gt;

&lt;p&gt;If you haven't created a Github repository yet, do that now. I called mine 'second-brain'. You can create it as private repository if you don't want others to read it.&lt;/p&gt;

&lt;p&gt;Make sure your device is able to access your Github repository and has a &lt;a href="https://docs.Github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token" rel="noopener noreferrer"&gt;personal access token&lt;/a&gt; setup.&lt;/p&gt;

&lt;h3&gt;
  
  
  .gitignore
&lt;/h3&gt;

&lt;p&gt;This is the &lt;code&gt;.gitignore&lt;/code&gt; file that we will be using. It excludes the trash folder from Obsidian and the &lt;code&gt;.obsidian&lt;/code&gt; config folder.&lt;/p&gt;

&lt;p&gt;We exclude the last one because Obsidian auto generates it for any vault. But since we will be using a specific config folder we don't need the default folder. &lt;/p&gt;

&lt;p&gt;Create that file and check it in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;.trash/
.obsidian
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configure Obsidian Git
&lt;/h2&gt;

&lt;p&gt;To sync the repository we will be using a Obsidian.md plugin called &lt;a href="https://Github.com/denolehov/obsidian-git" rel="noopener noreferrer"&gt;Obsidian Git&lt;/a&gt;. This plugin integrates and automates syncing with Github. Make sure to install it and enable it. Again, it will only work if you have setup your personal access token for Github.&lt;/p&gt;

&lt;p&gt;Make sure to clone the new repository. Open the folder with Obsidian.md via &lt;code&gt;Open folder as vault&lt;/code&gt;. Now you should see a default Obsidian installation. Browse to &lt;code&gt;⚙️ &amp;gt; Community Plugin &amp;gt; Browse&lt;/code&gt; and install Obsidian Git. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy2pc0a8o2ulqth6dchfx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy2pc0a8o2ulqth6dchfx.png" alt="Search for Obsidian Git plugin"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Under settings &lt;code&gt;⚙️ &amp;gt; Obsidian Git&lt;/code&gt; you can fine tune the plugin. Set a positive value to &lt;code&gt;Vault backup interval&lt;/code&gt; and &lt;code&gt;Auto pull interval&lt;/code&gt; to automate git. Scroll through and make adjustments if needed. Though the default settings are great for most uses.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi5sbrsf73xptxqzsvmqb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi5sbrsf73xptxqzsvmqb.png" alt="Configure Obsidian Git"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure that the plugin works. Create some notes and either wait for the automation to happen or use the git UI within obsidian.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fric3m9ms81i4kj9xzrgz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fric3m9ms81i4kj9xzrgz.png" alt="Obsidian Git UI Integration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Config Folders
&lt;/h2&gt;

&lt;p&gt;Right know I have multiple laptops, a PC and an IPhone where Obsidian is installed. It would be a hassle to sync them by hand. &lt;/p&gt;

&lt;p&gt;Some plugins are not available on the IPhone, so I can't use the standard &lt;code&gt;.obsidian&lt;/code&gt; folder as all configurations and plugins will be managed in this place.&lt;/p&gt;

&lt;p&gt;The solution for this problem is to use different config folders for these devices.&lt;/p&gt;

&lt;p&gt;I use two config folders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.obsidian.desktop&lt;/code&gt; (config for all laptops and PCs)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.obsidian.mobile&lt;/code&gt; (config for my IPhone)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The naming is of course is up to you. You could also make folders for different OSs, e.g.: &lt;code&gt;.obsidian.linux&lt;/code&gt;, &lt;code&gt;.obsidian.mac&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Switching The Config Folders
&lt;/h2&gt;

&lt;p&gt;Under settings &lt;code&gt;⚙️ &amp;gt; About &amp;gt; Override config folder&lt;/code&gt; you can now define which folder to use. If you're on a laptop or PC right now, use &lt;code&gt;.obsidian.desktop&lt;/code&gt;. Type that into the text box.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7t0gonxvkgscyksp5dt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7t0gonxvkgscyksp5dt.png" alt="Switching  the config folder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Relaunch the app now. You now should be using the new config folder. To check if you're using the new config folder go back to the settings and see if the input field contains your new config folder. &lt;/p&gt;

&lt;p&gt;The cool thing is: The config folder that you now specified is checked into the git repository. This ensures that all configurations get backed up for this device. This also happens with any &lt;code&gt;.obsidian.*&lt;/code&gt; folder for other devices. Just the default &lt;code&gt;.obsidian&lt;/code&gt; folder will be ignored.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding A New Device
&lt;/h2&gt;

&lt;p&gt;If you want to add a device to use obsidian you just need to clone your repository to that device and repeat the steps that I described above.&lt;/p&gt;

&lt;h2&gt;
  
  
  Migrating existing .obsidian config folders
&lt;/h2&gt;

&lt;p&gt;If you already have a configured Obsidian instance you can just copy the &lt;code&gt;.obsidian&lt;/code&gt; folder and rename it to your liking. After that you just change the config folder in the settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;p&gt;Sometimes you will have random merge conflicts. These happen because sometimes obsidian changes the workspace files. For example when you zoom in the graph view. If you just started the app you can safley &lt;code&gt;git reset --hard origin/head&lt;/code&gt;. This resets the vault to the current github state. After that your changes get backed up again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;There you have it. An easy way to manage your Obsidian.md vault on multiple devices using just one Github repository.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>obsidian</category>
      <category>github</category>
    </item>
    <item>
      <title>Get Mapped Object Inside a Callback Function</title>
      <dc:creator>Steve</dc:creator>
      <pubDate>Mon, 12 Jul 2021 17:37:21 +0000</pubDate>
      <link>https://forem.com/stvbyr/get-mapped-object-inside-a-callback-function-493j</link>
      <guid>https://forem.com/stvbyr/get-mapped-object-inside-a-callback-function-493j</guid>
      <description>&lt;p&gt;Sometimes when using array map you maybe want to access the referenced object that is mapped over.&lt;/p&gt;

&lt;p&gt;If you use a closure you can just reference the mapped object by its name as the closure has access to the outer scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Olive&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ty&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hugo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ginger&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`Took &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; from names(&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; entries)`&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Array(4) [ &lt;/span&gt;
&lt;span class="c1"&gt;//     0: "Took Olive from names(4 entries)"&lt;/span&gt;
&lt;span class="c1"&gt;//     1: "Took Ty from names(4 entries)"&lt;/span&gt;
&lt;span class="c1"&gt;//     2: "Took Hugo from names(4 entries)"&lt;/span&gt;
&lt;span class="c1"&gt;//     3: "Took Ginger from names(4 entries)"&lt;/span&gt;
&lt;span class="c1"&gt;// ​]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But if you wanna use a generic callback you can't do that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Olive&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ty&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hugo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ginger&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Yew&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ayelloribbin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;First&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Plant&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logStatusForNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`Took &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; from names(&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; entries)`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstNamesStatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstNames&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;logStatusForNames&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastNamesStatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;lastNames&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;logStatusForNames&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstNamesStatus&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lastNamesStatus&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// will not work because "names" is not specified anymore and I can't use any variable either&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unfortunately, but there is hope. &lt;/p&gt;

&lt;h2&gt;
  
  
  Method 1: Using the third argument of the callback
&lt;/h2&gt;

&lt;p&gt;Luckily there is a super easy fix for that. &lt;/p&gt;

&lt;p&gt;The callback function actually can take three parameters as its arguments. &lt;/p&gt;

&lt;p&gt;The first one is the value of a single array element. &lt;/p&gt;

&lt;p&gt;The second one is the index of that element. &lt;/p&gt;

&lt;p&gt;And finally the third parameter is a reference to the object that is mapped over.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Olive&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ty&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hugo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ginger&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Yew&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ayelloribbin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;First&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Plant&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logStatusForNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`Took &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; from names(&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; entries)`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstNamesStatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstNames&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;logStatusForNames&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastNamesStatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;lastNames&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;logStatusForNames&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstNamesStatus&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lastNamesStatus&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Array(4) [ &lt;/span&gt;
&lt;span class="c1"&gt;//     0: "Took Olive from names(4 entries)"&lt;/span&gt;
&lt;span class="c1"&gt;//     1: "Took Ty from names(4 entries)"&lt;/span&gt;
&lt;span class="c1"&gt;//     2: "Took Hugo from names(4 entries)"&lt;/span&gt;
&lt;span class="c1"&gt;//     3: "Took Ginger from names(4 entries)"&lt;/span&gt;
&lt;span class="c1"&gt;// ​]&lt;/span&gt;
&lt;span class="c1"&gt;// Array(4) [ &lt;/span&gt;
&lt;span class="c1"&gt;//     0: "Took Yew from names(4 entries)"&lt;/span&gt;
&lt;span class="c1"&gt;//     1: "Took Ayelloribbin from names(4 entries)"&lt;/span&gt;
&lt;span class="c1"&gt;//     2: "Took First from names(4 entries)"&lt;/span&gt;
&lt;span class="c1"&gt;//     3: "Took Plant from names(4 entries)"&lt;/span&gt;
&lt;span class="c1"&gt;// ​]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! Easy right?&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 2: Setting the &lt;code&gt;thisArg&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Technically there is another approach to this. &lt;/p&gt;

&lt;p&gt;You can give the map function a second argument. It will determine what &lt;code&gt;this&lt;/code&gt; refers to inside the callback function. &lt;/p&gt;

&lt;p&gt;But I do &lt;em&gt;not&lt;/em&gt; recommend that as the use of &lt;code&gt;this&lt;/code&gt; should be used in small doses. Or avoided if possible.&lt;/p&gt;

&lt;p&gt;There is another caveat though. You can't use arrow functions when using that method. This relates to how arrow functions are implemented in javascript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Olive&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ty&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hugo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ginger&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Yew&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ayelloribbin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;First&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Plant&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logStatusForNamesFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Took &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; from names(&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; entries)`&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logStatusForNamesArrow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`Took &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; from names(&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; entries)`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstNamesStatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstNames&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;logStatusForNamesFunction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;firstNames&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// works as in the previous example&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastNamesStatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;lastNames&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;logStatusForNamesArrow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lastNames&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// doesn't work. "this" refers to the window object if called in a browser&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstNamesStatus&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lastNamesStatus&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;As you can see it is very easy to reference the mapped object inside a array map callback.&lt;/p&gt;

&lt;p&gt;By the way the first method that I showed you also works with &lt;code&gt;reduce&lt;/code&gt;. The callback can take up to four arguments. The fourth one would be the reduced array.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
