A quick method to verify duplicate entries using hash

I kept coming back to creating methods that checked if a combination of fields is unique, and ended up creating a simple method, and wanted record it here.

This is for TypeScript. I am a newbie in coding world, so if there is a suggestion or something better, I'd love to hear!

import { createHash } from 'crypto';

function getHash(input: string[]) {
    const _now = new Date().toString();
    const _hashString = input.join(' ') + _now;
    const hash = createHash('sha256');
    hash.update(_hashString);
    return hash.digest('hex').toString();
  }

You can pass an array of strings to the method to create a unique hash.

getHash([item.serialNumber, item.deviceModel])

Just a nice code snippet.

Happy Coding!